Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: adding a shim layer for Resource Manager #14220

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ func Default() UserFeatures {
RollInstancesWhenRequired: true,
ScaleToZeroOnDelete: true,
},
Storage: StorageFeatures{
UseResourceManager: false,
},
}
}
5 changes: 5 additions & 0 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type UserFeatures struct {
TemplateDeployment TemplateDeploymentFeatures
LogAnalyticsWorkspace LogAnalyticsWorkspaceFeatures
ResourceGroup ResourceGroupFeatures
Storage StorageFeatures
}

type CognitiveAccountFeatures struct {
Expand Down Expand Up @@ -60,3 +61,7 @@ type ApiManagementFeatures struct {
type ApplicationInsightFeatures struct {
DisableGeneratedRule bool
}

type StorageFeatures struct {
UseResourceManager bool
}
24 changes: 24 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
},
},

"storage": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*schema.Schema{
"use_resource_manager": {
Type: pluginsdk.TypeBool,
Optional: true,
},
},
},
},

"template_deployment": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -355,6 +369,16 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["storage"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
storageRaw := items[0].(map[string]interface{})
if v, ok := storageRaw["use_resource_manager"]; ok {
featuresMap.Storage.UseResourceManager = v.(bool)
}
}
}

if raw, ok := val["template_deployment"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
Expand Down
84 changes: 84 additions & 0 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func TestExpandFeatures(t *testing.T) {
ResourceGroup: features.ResourceGroupFeatures{
PreventDeletionIfContainsResources: true,
},
Storage: features.StorageFeatures{
UseResourceManager: false,
},
},
},
{
Expand Down Expand Up @@ -127,6 +130,11 @@ func TestExpandFeatures(t *testing.T) {
"scale_to_zero_before_deletion": true,
},
},
"storage": []interface{}{
map[string]interface{}{
"use_resource_manager": true,
},
},
},
},
Expected: features.UserFeatures{
Expand Down Expand Up @@ -170,6 +178,9 @@ func TestExpandFeatures(t *testing.T) {
ForceDelete: true,
ScaleToZeroOnDelete: true,
},
Storage: features.StorageFeatures{
UseResourceManager: true,
},
},
},
{
Expand Down Expand Up @@ -239,6 +250,11 @@ func TestExpandFeatures(t *testing.T) {
"scale_to_zero_before_deletion": false,
},
},
"storage": []interface{}{
map[string]interface{}{
"use_resource_manager": false,
},
},
},
},
Expected: features.UserFeatures{
Expand Down Expand Up @@ -282,6 +298,9 @@ func TestExpandFeatures(t *testing.T) {
RollInstancesWhenRequired: false,
ScaleToZeroOnDelete: false,
},
Storage: features.StorageFeatures{
UseResourceManager: false,
},
},
},
}
Expand Down Expand Up @@ -1025,3 +1044,68 @@ func TestExpandFeaturesResourceGroup(t *testing.T) {
}
}
}

func TestExpandFeaturesStorage(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"use_resource_manager": []interface{}{},
},
},
Expected: features.UserFeatures{
Storage: features.StorageFeatures{
UseResourceManager: false,
},
},
},
{
Name: "Use Resource Manager Enabled",
Input: []interface{}{
map[string]interface{}{
"storage": []interface{}{
map[string]interface{}{
"use_resource_manager": true,
},
},
},
},
Expected: features.UserFeatures{
Storage: features.StorageFeatures{
UseResourceManager: true,
},
},
},
{
Name: "Use Resource Manager Disabled",
Input: []interface{}{
map[string]interface{}{
"storage": []interface{}{
map[string]interface{}{
"use_resource_manager": false,
},
},
},
},
Expected: features.UserFeatures{
Storage: features.StorageFeatures{
UseResourceManager: false,
},
},
},
}

for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.Storage, testCase.Expected.Storage) {
t.Fatalf("Expected %+v but got %+v", result.Storage, testCase.Expected.Storage)
}
}
}
Loading