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

r/(linux|windows)_virtual_machine(_scale_set): support for Force Delete #11216

Merged
merged 17 commits into from
May 26, 2021
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
6 changes: 4 additions & 2 deletions azurerm/internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ func Default() UserFeatures {
DeleteNestedItemsDuringDeletion: true,
},
VirtualMachine: VirtualMachineFeatures{
DeleteOSDiskOnDeletion: true,
GracefulShutdown: false,
DeleteOSDiskOnDeletion: true,
GracefulShutdown: false,
SkipShutdownAndForceDelete: false,
},
VirtualMachineScaleSet: VirtualMachineScaleSetFeatures{
ForceDelete: false,
RollInstancesWhenRequired: true,
},
}
Expand Down
6 changes: 4 additions & 2 deletions azurerm/internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ type UserFeatures struct {
}

type VirtualMachineFeatures struct {
DeleteOSDiskOnDeletion bool
GracefulShutdown bool
DeleteOSDiskOnDeletion bool
GracefulShutdown bool
SkipShutdownAndForceDelete bool
}

type VirtualMachineScaleSetFeatures struct {
ForceDelete bool
RollInstancesWhenRequired bool
}

Expand Down
15 changes: 15 additions & 0 deletions azurerm/internal/provider/features.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
)
Expand Down Expand Up @@ -84,6 +85,10 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
Type: pluginsdk.TypeBool,
Optional: true,
},
"skip_shutdown_and_force_delete": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
Expand All @@ -94,6 +99,10 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"force_delete": {
Type: pluginsdk.TypeBool,
Optional: true,
},
"roll_instances_when_required": {
Type: pluginsdk.TypeBool,
Required: true,
Expand Down Expand Up @@ -189,6 +198,9 @@ func expandFeatures(input []interface{}) features.UserFeatures {
if v, ok := virtualMachinesRaw["graceful_shutdown"]; ok {
features.VirtualMachine.GracefulShutdown = v.(bool)
}
if v, ok := virtualMachinesRaw["skip_shutdown_and_force_delete"]; ok {
features.VirtualMachine.SkipShutdownAndForceDelete = v.(bool)
}
}
}

Expand All @@ -199,6 +211,9 @@ func expandFeatures(input []interface{}) features.UserFeatures {
if v, ok := scaleSetRaw["roll_instances_when_required"]; ok {
features.VirtualMachineScaleSet.RollInstancesWhenRequired = v.(bool)
}
if v, ok := scaleSetRaw["force_delete"]; ok {
features.VirtualMachineScaleSet.ForceDelete = v.(bool)
}
}
}

Expand Down
150 changes: 116 additions & 34 deletions azurerm/internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeletedKeyVaults: true,
},
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: false,
},
Network: features.NetworkFeatures{
RelaxedLocking: false,
},
TemplateDeployment: features.TemplateDeploymentFeatures{
DeleteNestedItemsDuringDeletion: true,
},
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: true,
DeleteOSDiskOnDeletion: true,
GracefulShutdown: false,
SkipShutdownAndForceDelete: false,
},
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
ForceDelete: false,
RollInstancesWhenRequired: true,
},
LogAnalyticsWorkspace: features.LogAnalyticsWorkspaceFeatures{
PermanentlyDeleteOnDestroy: false,
},
},
},
{
Expand Down Expand Up @@ -66,13 +69,15 @@ func TestExpandFeatures(t *testing.T) {
},
"virtual_machine": []interface{}{
map[string]interface{}{
"delete_os_disk_on_deletion": true,
"graceful_shutdown": true,
"delete_os_disk_on_deletion": true,
"graceful_shutdown": true,
"skip_shutdown_and_force_delete": true,
},
},
"virtual_machine_scale_set": []interface{}{
map[string]interface{}{
"roll_instances_when_required": true,
"force_delete": true,
},
},
},
Expand All @@ -92,22 +97,29 @@ func TestExpandFeatures(t *testing.T) {
DeleteNestedItemsDuringDeletion: true,
},
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: true,
GracefulShutdown: true,
DeleteOSDiskOnDeletion: true,
GracefulShutdown: true,
SkipShutdownAndForceDelete: true,
},
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
RollInstancesWhenRequired: true,
ForceDelete: true,
},
},
},
{
Name: "Complete Disabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine": []interface{}{
"key_vault": []interface{}{
map[string]interface{}{
"delete_os_disk_on_deletion": false,
"graceful_shutdown": false,
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted_key_vaults": false,
},
},
"log_analytics_workspace": []interface{}{
map[string]interface{}{
"permanently_delete_on_destroy": false,
},
},
"network_locking": []interface{}{
Expand All @@ -120,20 +132,17 @@ func TestExpandFeatures(t *testing.T) {
"delete_nested_items_during_deletion": false,
},
},
"virtual_machine_scale_set": []interface{}{
map[string]interface{}{
"roll_instances_when_required": false,
},
},
"key_vault": []interface{}{
"virtual_machine": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted_key_vaults": false,
"delete_os_disk_on_deletion": false,
"graceful_shutdown": false,
"skip_shutdown_and_force_delete": false,
},
},
"log_analytics_workspace": []interface{}{
"virtual_machine_scale_set": []interface{}{
map[string]interface{}{
"permanently_delete_on_destroy": false,
"force_delete": false,
"roll_instances_when_required": false,
},
},
},
Expand All @@ -153,10 +162,12 @@ func TestExpandFeatures(t *testing.T) {
DeleteNestedItemsDuringDeletion: false,
},
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: false,
GracefulShutdown: false,
DeleteOSDiskOnDeletion: false,
GracefulShutdown: false,
SkipShutdownAndForceDelete: false,
},
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
ForceDelete: false,
RollInstancesWhenRequired: false,
},
},
Expand Down Expand Up @@ -388,46 +399,94 @@ func TestExpandFeaturesVirtualMachine(t *testing.T) {
},
Expected: features.UserFeatures{
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: true,
GracefulShutdown: false,
DeleteOSDiskOnDeletion: true,
GracefulShutdown: false,
SkipShutdownAndForceDelete: false,
},
},
},
{
Name: "Delete OS Disk and Graceful Shutdown Enabled",
Name: "Delete OS Disk Enabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine": []interface{}{
map[string]interface{}{
"delete_os_disk_on_deletion": true,
"graceful_shutdown": true,
"graceful_shutdown": false,
"force_delete": false,
"shutdown_before_deletion": false,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: true,
GracefulShutdown: true,
DeleteOSDiskOnDeletion: true,
GracefulShutdown: false,
SkipShutdownAndForceDelete: false,
},
},
},
{
Name: "Delete OS Disk and Graceful Shutdown Disabled",
Name: "Graceful Shutdown Enabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine": []interface{}{
map[string]interface{}{
"delete_os_disk_on_deletion": false,
"graceful_shutdown": false,
"graceful_shutdown": true,
"force_delete": false,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: false,
GracefulShutdown: true,
SkipShutdownAndForceDelete: false,
},
},
},
{
Name: "Skip Shutdown and Force Delete Enabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine": []interface{}{
map[string]interface{}{
"delete_os_disk_on_deletion": false,
"graceful_shutdown": false,
"skip_shutdown_and_force_delete": true,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: false,
GracefulShutdown: false,
SkipShutdownAndForceDelete: true,
},
},
},
{
Name: "All Disabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine": []interface{}{
map[string]interface{}{
"delete_os_disk_on_deletion": false,
"graceful_shutdown": false,
"skip_shutdown_and_force_delete": false,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachine: features.VirtualMachineFeatures{
DeleteOSDiskOnDeletion: false,
GracefulShutdown: false,
DeleteOSDiskOnDeletion: false,
GracefulShutdown: false,
SkipShutdownAndForceDelete: false,
},
},
},
Expand Down Expand Up @@ -462,36 +521,59 @@ func TestExpandFeaturesVirtualMachineScaleSet(t *testing.T) {
},
},
},
{
Name: "Force Delete Enabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine_scale_set": []interface{}{
map[string]interface{}{
"force_delete": true,
"roll_instances_when_required": false,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
ForceDelete: true,
RollInstancesWhenRequired: false,
},
},
},
{
Name: "Roll Instances Enabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine_scale_set": []interface{}{
map[string]interface{}{
"force_delete": false,
"roll_instances_when_required": true,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
ForceDelete: false,
RollInstancesWhenRequired: true,
},
},
},
{
Name: "Roll Instances Disabled",
Name: "All Fields Disabled",
Input: []interface{}{
map[string]interface{}{
"virtual_machine_scale_set": []interface{}{
map[string]interface{}{
"force_delete": false,
"roll_instances_when_required": false,
},
},
},
},
Expected: features.UserFeatures{
VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{
ForceDelete: false,
RollInstancesWhenRequired: false,
},
},
Expand Down
Loading