Skip to content

Commit

Permalink
Merge pull request #10528 from terraform-providers/f/vmss-extensions-ga
Browse files Browse the repository at this point in the history
VMSS in-line extensions GA
  • Loading branch information
tombuildsstuff authored Feb 10, 2021
2 parents 66f00fb + 14e6206 commit f5dbf97
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 155 deletions.
14 changes: 0 additions & 14 deletions azurerm/internal/features/beta_features_opt_in.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ func TestAccLinuxVirtualMachineScaleSet_extensionBasic(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -88,8 +87,7 @@ func TestAccLinuxVirtualMachineScaleSet_extensionOnlySettings(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -104,16 +102,14 @@ func TestAccLinuxVirtualMachineScaleSet_extensionForceUpdateTag(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionForceUpdateTag(data, "second"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -128,8 +124,7 @@ func TestAccLinuxVirtualMachineScaleSet_extensionsMultiple(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings", "extension.1.protected_settings"),
})
}

Expand All @@ -144,24 +139,21 @@ func TestAccLinuxVirtualMachineScaleSet_extensionsUpdate(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionUpdate(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionBasic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -176,8 +168,7 @@ func TestAccLinuxVirtualMachineScaleSet_extensionWithTimeBudget(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -192,24 +183,21 @@ func TestAccLinuxVirtualMachineScaleSet_extensionWithTimeBudgetUpdate(t *testing
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionWithTimeBudget(data, "PT1H"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionWithTimeBudget(data, "PT30M"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -224,8 +212,7 @@ func TestAccLinuxVirtualMachineScaleSet_extensionTimeBudgetWithoutExtensions(t *
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand All @@ -240,24 +227,21 @@ func TestAccLinuxVirtualMachineScaleSet_extensionTimeBudgetWithoutExtensionsUpda
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionTimeBudgetWithoutExtensions(data, "PT1H"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionTimeBudgetWithoutExtensions(data, "PT30M"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
// TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta
data.ImportStep("admin_password", "extension"),
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

Expand Down Expand Up @@ -556,7 +540,6 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
protected_settings = jsonencode({
"managedIdentity" = {}
})
}
extension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
azValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
Expand Down Expand Up @@ -421,12 +420,10 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta inte
},
}

if features.VMSSExtensionsBeta() {
if vmExtensionsRaw, ok := d.GetOk("extension"); ok {
virtualMachineProfile.ExtensionProfile, err = expandVirtualMachineScaleSetExtensions(vmExtensionsRaw.([]interface{}))
if err != nil {
return err
}
if vmExtensionsRaw, ok := d.GetOk("extension"); ok {
virtualMachineProfile.ExtensionProfile, err = expandVirtualMachineScaleSetExtensions(vmExtensionsRaw.([]interface{}))
if err != nil {
return err
}
}

Expand Down Expand Up @@ -804,22 +801,14 @@ func resourceLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta inte
update.Sku = sku
}

if features.VMSSExtensionsBeta() {
if d.HasChange("extension") {
updateInstances = true

extensionProfile, err := expandVirtualMachineScaleSetExtensions(d.Get("extension").([]interface{}))
if err != nil {
return err
}
updateProps.VirtualMachineProfile.ExtensionProfile = extensionProfile
}
}
if d.HasChanges("extension", "extensions_time_budget") {
updateInstances = true

if d.HasChange("extensions_time_budget") {
if updateProps.VirtualMachineProfile.ExtensionProfile == nil {
updateProps.VirtualMachineProfile.ExtensionProfile = &compute.VirtualMachineScaleSetExtensionProfile{}
extensionProfile, err := expandVirtualMachineScaleSetExtensions(d.Get("extension").([]interface{}))
if err != nil {
return err
}
updateProps.VirtualMachineProfile.ExtensionProfile = extensionProfile
updateProps.VirtualMachineProfile.ExtensionProfile.ExtensionsTimeBudget = utils.String(d.Get("extensions_time_budget").(string))
}

Expand Down Expand Up @@ -1006,13 +995,11 @@ func resourceLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta interf
}
}

if features.VMSSExtensionsBeta() {
extensionProfile, err := flattenVirtualMachineScaleSetExtensions(profile.ExtensionProfile, d)
if err != nil {
return fmt.Errorf("failed flattening `extension`: %+v", err)
}
d.Set("extension", extensionProfile)
extensionProfile, err := flattenVirtualMachineScaleSetExtensions(profile.ExtensionProfile, d)
if err != nil {
return fmt.Errorf("failed flattening `extension`: %+v", err)
}
d.Set("extension", extensionProfile)

extensionsTimeBudget := "PT1H30M"
if profile.ExtensionProfile != nil && profile.ExtensionProfile.ExtensionsTimeBudget != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,15 +1437,15 @@ func expandVirtualMachineScaleSetExtensions(input []interface{}) (*compute.Virtu
extensionProps.ForceUpdateTag = utils.String(forceUpdateTag.(string))
}

if val, ok := extensionRaw["settings"]; ok {
if val, ok := extensionRaw["settings"]; ok && val.(string) != "" {
settings, err := structure.ExpandJsonFromString(val.(string))
if err != nil {
return nil, fmt.Errorf("failed to parse JSON from `settings`: %+v", err)
}
extensionProps.Settings = settings
}

if val, ok := extensionRaw["protected_settings"]; ok {
if val, ok := extensionRaw["protected_settings"]; ok && val.(string) != "" {
protectedSettings, err := structure.ExpandJsonFromString(val.(string))
if err != nil {
return nil, fmt.Errorf("failed to parse JSON from `protected_settings`: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-01/compute"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
)
Expand Down Expand Up @@ -97,22 +96,19 @@ func importVirtualMachineScaleSet(osType compute.OperatingSystemTypes, resourceT
d.Set("admin_password", "ignored-as-imported")
}

if features.VMSSExtensionsBeta() {
if vm.VirtualMachineScaleSetProperties.VirtualMachineProfile.ExtensionProfile != nil {
if extensionsProfile := vm.VirtualMachineScaleSetProperties.VirtualMachineProfile.ExtensionProfile; extensionsProfile != nil {
for _, v := range *extensionsProfile.Extensions {
v.ProtectedSettings = ""
}
updatedExtensions, err := flattenVirtualMachineScaleSetExtensions(extensionsProfile, d)
if err != nil {
return []*schema.ResourceData{}, fmt.Errorf("could not read VMSS extensions data for %q (resource group %q)", id.Name, id.ResourceGroup)
}
d.Set("extension", updatedExtensions)
var updatedExtensions []map[string]interface{}
if vm.VirtualMachineScaleSetProperties.VirtualMachineProfile.ExtensionProfile != nil {
if extensionsProfile := vm.VirtualMachineScaleSetProperties.VirtualMachineProfile.ExtensionProfile; extensionsProfile != nil {
for _, v := range *extensionsProfile.Extensions {
v.ProtectedSettings = ""
}
updatedExtensions, err = flattenVirtualMachineScaleSetExtensions(extensionsProfile, d)
if err != nil {
return []*schema.ResourceData{}, fmt.Errorf("could not read VMSS extensions data for %q (resource group %q)", id.Name, id.ResourceGroup)
}
}
} else {
d.Set("extension", []map[string]interface{}{})
}
d.Set("extension", updatedExtensions)

return []*schema.ResourceData{d}, nil
}
Expand Down
Loading

0 comments on commit f5dbf97

Please sign in to comment.