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

Tackling various vmss issues #448

Merged
merged 3 commits into from
Oct 21, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
166 changes: 162 additions & 4 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Required: true,
},

"accelerated_networking": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe omit zero value here?

},

"network_security_group_id": {
Type: schema.TypeString,
Optional: true,
},

"ip_configuration": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -279,6 +290,36 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"primary": {
Type: schema.TypeBool,
Optional: true,
},

"public_ip_address_configuration": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"idle_timeout": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(4, 32),
},

"domain_name_label": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
},
},
Expand All @@ -287,6 +328,25 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Set: resourceArmVirtualMachineScaleSetNetworkConfigurationHash,
},

"boot_diagnostics": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"storage_uri": {
Type: schema.TypeString,
Required: true,
},
},
},
},

"storage_profile_os_disk": {
Type: schema.TypeSet,
Required: true,
Expand Down Expand Up @@ -563,6 +623,11 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf
SinglePlacementGroup: &singlePlacementGroup,
}

if _, ok := d.GetOk("boot_diagnostics"); ok {
diagnosticProfile := expandAzureRMVirtualMachineScaleSetsDiagnosticProfile(d)
scaleSetProps.VirtualMachineProfile.DiagnosticsProfile = &diagnosticProfile
}

scaleSetParams := compute.VirtualMachineScaleSet{
Name: &name,
Location: &location,
Expand Down Expand Up @@ -648,6 +713,12 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac
}
}

if properties.VirtualMachineProfile.DiagnosticsProfile != nil {
if err := d.Set("boot_diagnostics", flattenAzureRmVirtualMachineScaleSetBootDiagnostics(properties.VirtualMachineProfile.DiagnosticsProfile.BootDiagnostics)); err != nil {
return fmt.Errorf("[DEBUG] Error setting Virutal Machine Scale Set Boot Diagnostics: %#v", err)
}
}

if properties.VirtualMachineProfile.OsProfile.WindowsConfiguration != nil {
if err := d.Set("os_profile_windows_config", flattenAzureRmVirtualMachineScaleSetOsProfileWindowsConfig(properties.VirtualMachineProfile.OsProfile.WindowsConfiguration)); err != nil {
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Scale Set OS Profile Windows config error: %#v", err)
Expand Down Expand Up @@ -814,13 +885,27 @@ func flattenAzureRmVirtualMachineScaleSetOsProfileSecrets(secrets *[]compute.Vau
return result
}

func flattenAzureRmVirtualMachineScaleSetBootDiagnostics(bootDiagnostic *compute.BootDiagnostics) []interface{} {
b := map[string]interface{}{
"enabled": *bootDiagnostic.Enabled,
"storage_uri": *bootDiagnostic.StorageURI,
}

return []interface{}{b}
}

func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.VirtualMachineScaleSetNetworkProfile) []map[string]interface{} {
networkConfigurations := profile.NetworkInterfaceConfigurations
result := make([]map[string]interface{}, 0, len(*networkConfigurations))
for _, netConfig := range *networkConfigurations {
s := map[string]interface{}{
"name": *netConfig.Name,
"primary": *netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.Primary,
"name": *netConfig.Name,
"primary": *netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.Primary,
"accelerated_networking": *netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.EnableAcceleratedNetworking,
}

if v := netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.NetworkSecurityGroup; v != nil {
s["network_security_group_id"] = *v.ID
}

if netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations != nil {
Expand Down Expand Up @@ -851,6 +936,20 @@ func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.Virtual
config["load_balancer_inbound_nat_rules_ids"] = schema.NewSet(schema.HashString, inboundNatPools)
}

if properties.Primary != nil {
config["primary"] = *properties.Primary
}

if properties.PublicIPAddressConfiguration != nil {
publicIpInfo := properties.PublicIPAddressConfiguration
publicIpConfigs := make([]map[string]interface{}, 0, 1)
publicIpConfig := make(map[string]interface{})
publicIpConfig["name"] = *publicIpInfo.Name
publicIpConfig["domain_name_label"] = *publicIpInfo.VirtualMachineScaleSetPublicIPAddressConfigurationProperties.DNSSettings
publicIpConfig["idle_timeout"] = *publicIpInfo.VirtualMachineScaleSetPublicIPAddressConfigurationProperties.IdleTimeoutInMinutes
config["public_ip_address_configuration"] = publicIpConfigs
}

ipConfigs = append(ipConfigs, config)
}

Expand Down Expand Up @@ -1124,6 +1223,7 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *

name := config["name"].(string)
primary := config["primary"].(bool)
acceleratedNetworking := config["accelerated_networking"].(bool)

ipConfigurationConfigs := config["ip_configuration"].([]interface{})
ipConfigurations := make([]compute.VirtualMachineScaleSetIPConfiguration, 0, len(ipConfigurationConfigs))
Expand Down Expand Up @@ -1165,17 +1265,56 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *
ipConfiguration.LoadBalancerInboundNatPools = &rulesResources
}

if v := ipconfig["primary"]; v != nil {
primary := v.(bool)
ipConfiguration.Primary = &primary
}

if v := ipconfig["public_ip_address_configuration"]; v != nil {
publicIpConfigs := v.([]interface{})
for _, publicIpConfigConfig := range publicIpConfigs {
publicIpConfig := publicIpConfigConfig.(map[string]interface{})

domainNameLabel := publicIpConfig["domain_name_label"].(string)
dnsSettings := compute.VirtualMachineScaleSetPublicIPAddressConfigurationDNSSettings{
DomainNameLabel: &domainNameLabel,
}

idleTimeout := int32(publicIpConfig["idle_timeout"].(int))
prop := compute.VirtualMachineScaleSetPublicIPAddressConfigurationProperties{
DNSSettings: &dnsSettings,
IdleTimeoutInMinutes: &idleTimeout,
}

publicIPConfigName := publicIpConfig["name"].(string)
config := compute.VirtualMachineScaleSetPublicIPAddressConfiguration{
Name: &publicIPConfigName,
VirtualMachineScaleSetPublicIPAddressConfigurationProperties: &prop,
}
ipConfiguration.PublicIPAddressConfiguration = &config
}
}

ipConfigurations = append(ipConfigurations, ipConfiguration)
}

nProfile := compute.VirtualMachineScaleSetNetworkConfiguration{
Name: &name,
VirtualMachineScaleSetNetworkConfigurationProperties: &compute.VirtualMachineScaleSetNetworkConfigurationProperties{
Primary: &primary,
IPConfigurations: &ipConfigurations,
Primary: &primary,
IPConfigurations: &ipConfigurations,
EnableAcceleratedNetworking: &acceleratedNetworking,
},
}

if v := config["network_security_group_id"]; v != nil {
id := v.(string)
networkSecurityGroupId := compute.SubResource{
ID: &id,
}
nProfile.VirtualMachineScaleSetNetworkConfigurationProperties.NetworkSecurityGroup = &networkSecurityGroupId
}

networkProfileConfig = append(networkProfileConfig, nProfile)
}

Expand Down Expand Up @@ -1235,6 +1374,25 @@ func expandAzureRMVirtualMachineScaleSetsOsProfile(d *schema.ResourceData) (*com
return osProfile, nil
}

func expandAzureRMVirtualMachineScaleSetsDiagnosticProfile(d *schema.ResourceData) compute.DiagnosticsProfile {
bootDiagnosticConfigs := d.Get("boot_diagnostics").([]interface{})
bootDiagnosticConfig := bootDiagnosticConfigs[0].(map[string]interface{})

enabled := bootDiagnosticConfig["enabled"].(bool)
storageURI := bootDiagnosticConfig["storage_uri"].(string)

bootDiagnostic := &compute.BootDiagnostics{
Enabled: &enabled,
StorageURI: &storageURI,
}

diagnosticsProfile := compute.DiagnosticsProfile{
BootDiagnostics: bootDiagnostic,
}

return diagnosticsProfile
}

func expandAzureRMVirtualMachineScaleSetsStorageProfileOsDisk(d *schema.ResourceData) (*compute.VirtualMachineScaleSetOSDisk, error) {
osDiskConfigs := d.Get("storage_profile_os_disk").(*schema.Set).List()

Expand Down
Loading