Skip to content

Commit

Permalink
refactor expand for nil case setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Sep 1, 2020
1 parent 8da272d commit ab974d5
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions azurerm/internal/services/compute/virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,70 +1421,71 @@ func flattenVirtualMachineScaleSetExtensions(input *compute.VirtualMachineScaleS
}

for k, v := range *input.Extensions {
ext := make(map[string]interface{})
name := ""
if v.Name != nil {
name = *v.Name
}
ext["name"] = name

autoUpgradeMinorVersion := false
forceUpdateTag := ""
provisionAfterExtension := make([]interface{}, 0)
protectedSettings := ""
extPublisher := ""
extSettings := ""
extType := ""
extTypeVersion := ""

if props := v.VirtualMachineScaleSetExtensionProperties; props != nil {
extPublisher := ""
if props.Publisher != nil {
extPublisher = *props.Publisher
}
ext["publisher"] = extPublisher

extType := ""
if props.Type != nil {
extType = *props.Type
}
ext["type"] = extType

extTypeVersion := ""
if props.TypeHandlerVersion != nil {
extTypeVersion = *props.TypeHandlerVersion
}
ext["type_handler_version"] = extTypeVersion

autoUpgradeMinorVersion := false
if props.AutoUpgradeMinorVersion != nil {
autoUpgradeMinorVersion = *props.AutoUpgradeMinorVersion
}
ext["auto_upgrade_minor_version"] = autoUpgradeMinorVersion

forceUpdateTag := ""
if props.ForceUpdateTag != nil {
forceUpdateTag = *props.ForceUpdateTag
}
ext["force_update_tag"] = forceUpdateTag

provisionAfterExtension := make([]interface{}, 0)
if props.ProvisionAfterExtensions != nil {
provisionAfterExtension = utils.FlattenStringSlice(props.ProvisionAfterExtensions)
}
ext["provision_after_extensions"] = provisionAfterExtension

extSettings := ""
if props.Settings != nil {
extSettingsRaw, err := structure.FlattenJsonToString(props.Settings.(map[string]interface{}))
if err != nil {
return nil, err
}
extSettings = extSettingsRaw
}
ext["settings"] = extSettings

// protected_settings isn't returned, so we attempt to get it from config otherwise set to empty string
protectedSettings := ""
if protectedSettingsFromConfig, ok := d.GetOk(fmt.Sprintf("extension.%d.protected_settings", k)); ok {
if protectedSettingsFromConfig.(string) != "" && protectedSettingsFromConfig.(string) != "{}" {
protectedSettings = protectedSettingsFromConfig.(string)
}
}
// protected_settings isn't returned, so we attempt to get it from config otherwise set to empty string
if protectedSettingsFromConfig, ok := d.GetOk(fmt.Sprintf("extension.%d.protected_settings", k)); ok {
if protectedSettingsFromConfig.(string) != "" && protectedSettingsFromConfig.(string) != "{}" {
protectedSettings = protectedSettingsFromConfig.(string)
}
ext["protected_settings"] = protectedSettings
}
result = append(result, ext)

result = append(result, map[string]interface{}{
"name": name,
"auto_upgrade_minor_version": autoUpgradeMinorVersion,
"force_update_tag": forceUpdateTag,
"provision_after_extensions": provisionAfterExtension,
"protected_settings": protectedSettings,
"publisher": extPublisher,
"settings": extSettings,
"type": extType,
"type_handler_version": extTypeVersion,
})
}
return result, nil
}

0 comments on commit ab974d5

Please sign in to comment.