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

machine_learning - Add new machine_learning block that supports purge_soft_deleted_workspace_on_destroy #25624

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -60,6 +60,9 @@ func Default() UserFeatures {
PostgresqlFlexibleServer: PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
MachineLearning: MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: false,
},
RecoveryService: RecoveryServiceFeatures{
VMBackupStopProtectionAndRetainDataOnDestroy: false,
PurgeProtectedItemsFromVaultOnDestroy: false,
Expand Down
5 changes: 5 additions & 0 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type UserFeatures struct {
ManagedDisk ManagedDiskFeatures
Subscription SubscriptionFeatures
PostgresqlFlexibleServer PostgresqlFlexibleServerFeatures
MachineLearning MachineLearningFeatures
RecoveryService RecoveryServiceFeatures
}

Expand Down Expand Up @@ -87,6 +88,10 @@ type PostgresqlFlexibleServerFeatures struct {
RestartServerOnConfigurationValueChange bool
}

type MachineLearningFeatures struct {
PurgeSoftDeletedWorkspaceOnDestroy bool
}

type RecoveryServiceFeatures struct {
VMBackupStopProtectionAndRetainDataOnDestroy bool
PurgeProtectedItemsFromVaultOnDestroy bool
Expand Down
24 changes: 24 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,20 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
},
},
},
"machine_learning": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"purge_soft_deleted_workspace_on_destroy": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
},
},

"recovery_service": {
Type: pluginsdk.TypeList,
Expand Down Expand Up @@ -534,6 +548,16 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["machine_learning"]; ok {
items := raw.([]interface{})
if len(items) > 0 {
subscriptionRaw := items[0].(map[string]interface{})
if v, ok := subscriptionRaw["purge_soft_deleted_workspace_on_destroy"]; ok {
featuresMap.MachineLearning.PurgeSoftDeletedWorkspaceOnDestroy = v.(bool)
}
}
}

if raw, ok := val["recovery_service"]; 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 @@ -75,6 +75,9 @@ func TestExpandFeatures(t *testing.T) {
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
MachineLearning: features.MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: false,
},
RecoveryService: features.RecoveryServiceFeatures{
VMBackupStopProtectionAndRetainDataOnDestroy: false,
PurgeProtectedItemsFromVaultOnDestroy: false,
Expand Down Expand Up @@ -165,6 +168,11 @@ func TestExpandFeatures(t *testing.T) {
"scale_to_zero_before_deletion": true,
},
},
"machine_learning": []interface{}{
map[string]interface{}{
"purge_soft_deleted_workspace_on_destroy": true,
},
},
"recovery_service": []interface{}{
map[string]interface{}{
"vm_backup_stop_protection_and_retain_data_on_destroy": true,
Expand Down Expand Up @@ -228,6 +236,9 @@ func TestExpandFeatures(t *testing.T) {
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: true,
},
MachineLearning: features.MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: true,
},
RecoveryService: features.RecoveryServiceFeatures{
VMBackupStopProtectionAndRetainDataOnDestroy: true,
PurgeProtectedItemsFromVaultOnDestroy: true,
Expand Down Expand Up @@ -318,6 +329,11 @@ func TestExpandFeatures(t *testing.T) {
"scale_to_zero_before_deletion": false,
},
},
"machine_learning": []interface{}{
map[string]interface{}{
"purge_soft_deleted_workspace_on_destroy": false,
},
},
"recovery_service": []interface{}{
map[string]interface{}{
"vm_backup_stop_protection_and_retain_data_on_destroy": false,
Expand Down Expand Up @@ -381,6 +397,9 @@ func TestExpandFeatures(t *testing.T) {
PostgresqlFlexibleServer: features.PostgresqlFlexibleServerFeatures{
RestartServerOnConfigurationValueChange: false,
},
MachineLearning: features.MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: false,
},
RecoveryService: features.RecoveryServiceFeatures{
VMBackupStopProtectionAndRetainDataOnDestroy: false,
PurgeProtectedItemsFromVaultOnDestroy: false,
Expand Down Expand Up @@ -1383,6 +1402,71 @@ func TestExpandFeaturesPosgresqlFlexibleServer(t *testing.T) {
}
}

func TestExpandFeaturesMachineLearning(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"machine_learning": []interface{}{},
},
},
Expected: features.UserFeatures{
MachineLearning: features.MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: false,
},
},
},
{
Name: "MachineLearning Workspace purge soft delete on destroy",
Input: []interface{}{
map[string]interface{}{
"machine_learning": []interface{}{
map[string]interface{}{
"purge_soft_deleted_workspace_on_destroy": true,
},
},
},
},
Expected: features.UserFeatures{
MachineLearning: features.MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: true,
},
},
},
{
Name: "MachineLearning Workspace does not purge soft delete on destroy",
Input: []interface{}{
map[string]interface{}{
"machine_learning": []interface{}{
map[string]interface{}{
"purge_soft_deleted_workspace_on_destroy": false,
},
},
},
},
Expected: features.UserFeatures{
MachineLearning: features.MachineLearningFeatures{
PurgeSoftDeletedWorkspaceOnDestroy: false,
},
},
},
}

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

func TestExpandFeaturesRecoveryService(t *testing.T) {
testData := []struct {
Name string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,14 @@ func resourceMachineLearningWorkspaceDelete(d *pluginsdk.ResourceData, meta inte
return fmt.Errorf("parsing Machine Learning Workspace ID `%q`: %+v", d.Id(), err)
}

future, err := client.Delete(ctx, *id, workspaces.DefaultDeleteOperationOptions())
options := workspaces.DefaultDeleteOperationOptions()
if meta.(*clients.Client).Features.MachineLearning.PurgeSoftDeletedWorkspaceOnDestroy {
options = workspaces.DeleteOperationOptions{
ForceToPurge: pointer.To(true),
}
}

future, err := client.Delete(ctx, *id, options)
if err != nil {
return fmt.Errorf("deleting Machine Learning Workspace %q (Resource Group %q): %+v", id.WorkspaceName, id.ResourceGroupName, err)
}
Expand Down
Loading
Loading