Skip to content

Commit

Permalink
Support for VMSS in-line extensions behind feature flag (#8222)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Sep 1, 2020
1 parent 6ca1249 commit a2afa22
Show file tree
Hide file tree
Showing 51 changed files with 1,717 additions and 142 deletions.
14 changes: 14 additions & 0 deletions azurerm/internal/features/beta_features_opt_in.go
@@ -0,0 +1,14 @@
package features

import (
"os"
"strings"
)

// VMSSExtensionsBeta returns whether or not the beta for VMSS Extensions for Linux and Windows VMSS resources is
// enabled.
//
// Set the Environment Variable `ARM_PROVIDER_VMSS_EXTENSIONS_BETA` to `true`
func VMSSExtensionsBeta() bool {
return strings.EqualFold(os.Getenv("ARM_PROVIDER_VMSS_EXTENSIONS_BETA"), "true")
}
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"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 @@ -136,6 +137,8 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource {
}, false),
},

"extension": VirtualMachineScaleSetExtensionsSchema(),

"health_probe_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -262,15 +265,15 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
exists, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error checking for existing Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
if !utils.ResponseWasNotFound(exists.Response) {
return fmt.Errorf("checking for existing Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}

if !utils.ResponseWasNotFound(resp.Response) {
return tf.ImportAsExistsError("azurerm_linux_virtual_machine_scale_set", *resp.ID)
if !utils.ResponseWasNotFound(exists.Response) {
return tf.ImportAsExistsError("azurerm_linux_virtual_machine_scale_set", *exists.ID)
}

location := azure.NormalizeLocation(d.Get("location").(string))
Expand Down Expand Up @@ -394,6 +397,15 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
},
}

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

if adminPassword, ok := d.GetOk("admin_password"); ok {
virtualMachineProfile.OsProfile.AdminPassword = utils.String(adminPassword.(string))
}
Expand Down Expand Up @@ -488,7 +500,7 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i
log.Printf("[DEBUG] Virtual Machine Scale Set %q (Resource Group %q) was created", name, resourceGroup)

log.Printf("[DEBUG] Retrieving Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup)
resp, err = client.Get(ctx, resourceGroup, name)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand Down Expand Up @@ -728,6 +740,18 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i
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.HasChange("tags") {
update.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
}
Expand Down Expand Up @@ -905,6 +929,14 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int
return fmt.Errorf("Error setting `terminate_notification`: %+v", err)
}
}

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

if policy := props.UpgradePolicy; policy != nil {
Expand Down

0 comments on commit a2afa22

Please sign in to comment.