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 5 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 @@ -35,5 +35,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 @@ -52,3 +53,7 @@ type ResourceGroupFeatures struct {
type ApiManagementFeatures struct {
PurgeSoftDeleteOnDestroy 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 @@ -157,6 +157,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,
},
},
},
},
magodo marked this conversation as resolved.
Show resolved Hide resolved
}

// this is a temporary hack to enable us to gradually add provider blocks to test configurations
Expand Down Expand Up @@ -297,5 +311,15 @@ 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 {
features.Storage.UseResourceManager = v.(bool)
}
}
}
magodo marked this conversation as resolved.
Show resolved Hide resolved

return features
}
84 changes: 84 additions & 0 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func TestExpandFeatures(t *testing.T) {
ResourceGroup: features.ResourceGroupFeatures{
PreventDeletionIfContainsResources: false,
},
Storage: features.StorageFeatures{
UseResourceManager: false,
},
},
},
{
Expand Down Expand Up @@ -106,6 +109,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 @@ -141,6 +149,9 @@ func TestExpandFeatures(t *testing.T) {
ForceDelete: true,
ScaleToZeroOnDelete: true,
},
Storage: features.StorageFeatures{
UseResourceManager: true,
},
},
},
{
Expand Down Expand Up @@ -197,6 +208,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 @@ -232,6 +248,9 @@ func TestExpandFeatures(t *testing.T) {
RollInstancesWhenRequired: false,
ScaleToZeroOnDelete: false,
},
Storage: features.StorageFeatures{
UseResourceManager: false,
},
},
},
}
Expand Down Expand Up @@ -935,3 +954,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