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

Additional VMSS properties (issues #1210 & #1226 #1209

Merged
merged 2 commits into from
Jun 5, 2018
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ IMPROVEMENTS:
* `azurerm_app_service` - allow changing `client_affinity_enabled` without requiring a resource recreation ([#993](https://github.com/terraform-providers/terraform-provider-azurerm/issues/993))
* `azurerm_app_service` - support for configuring `LocalSCM` source control ([#826](https://github.com/terraform-providers/terraform-provider-azurerm/issues/826))
* `azurerm_app_service` - returning a clearer error message when the name (which needs to be globally unique) is in use ([#1037](https://github.com/terraform-providers/terraform-provider-azurerm/issues/1037))
* `azurerm_cosmosdb_account` - increasing the maximum value for `max_interval_in_seconds` from 100s to 86400s (1 day) [[#1000](https://github.com/terraform-providers/terraform-provider-azurerm/issues/1000)]
* `azurerm_cosmosdb_account` - increasing the maximum value for `max_interval_in_seconds` from 100s to 86400s (1 day) [[#1000](https://github.com/terraform-providers/terraform-provider-azurerm/issues/1000)]
* `azurerm_function_app` - returning a clearer error message when the name (which needs to be globally unique) is in use ([#1037](https://github.com/terraform-providers/terraform-provider-azurerm/issues/1037))
* `azurerm_network_interface` - support for attaching to Application Gateways ([#1027](https://github.com/terraform-providers/terraform-provider-azurerm/issues/1027))
* `azurerm_traffic_manager_endpoint` - adding support for `geo_mappings` ([#986](https://github.com/terraform-providers/terraform-provider-azurerm/issues/986))
Expand Down Expand Up @@ -352,4 +352,4 @@ IMPROVEMENTS:
* core - Upgrading `Azure/azure-sdk-for-go` to v11.2.2-beta ([#594](https://github.com/terraform-providers/terraform-provider-azurerm/issues/594))
* core - upgrading `Azure/go-autorest` to v9.5.2 ([#617](https://github.com/terraform-providers/terraform-provider-azurerm/issues/617))
* core - skipping Resource Provider Registration in AutoRest when opted-out ([#630](https://github.com/terraform-providers/terraform-provider-azurerm/issues/630))
* `azurerm_app_service` - exposing the Default Hostname as a Computed field
* `azurerm_app_service` - exposing the Default Hostname as a Computed field
61 changes: 59 additions & 2 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,32 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Optional: true,
},

"ip_forwarding": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

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

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

"ip_configuration": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -776,7 +797,6 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac
if upgradePolicy := properties.UpgradePolicy; upgradePolicy != nil {
d.Set("upgrade_policy_mode", upgradePolicy.Mode)
}

d.Set("overprovision", properties.Overprovision)
d.Set("single_placement_group", properties.SinglePlacementGroup)

Expand Down Expand Up @@ -1036,10 +1056,27 @@ func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.Virtual
s["accelerated_networking"] = *v
}

if v := netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.EnableIPForwarding; v != nil {
s["ip_forwarding"] = *v
}

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

if netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.DNSSettings != nil {
dnsSetting := make(map[string]interface{})
dnsServers := make([]string, 0, len(*netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.DNSSettings.DNSServers))
if netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.DNSSettings.DNSServers != nil {
for _, dnsServer := range *netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.DNSSettings.DNSServers {
dnsServers = append(dnsServers, dnsServer)
}
dnsSetting["dns_servers"] = dnsServers
}

s["dns_settings"] = []interface{}{dnsSetting}
}

if netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations != nil {
ipConfigs := make([]map[string]interface{}, 0, len(*netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations))
for _, ipConfig := range *netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations {
Expand Down Expand Up @@ -1394,7 +1431,25 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *
name := config["name"].(string)
primary := config["primary"].(bool)
acceleratedNetworking := config["accelerated_networking"].(bool)

ipForwarding := config["ip_forwarding"].(bool)

dnsSettingsConfigs := config["dns_settings"].([]interface{})
dnsSettings := compute.VirtualMachineScaleSetNetworkConfigurationDNSSettings{}
for _, dnsSettingsConfig := range dnsSettingsConfigs {
dns_settings := dnsSettingsConfig.(map[string]interface{})

if v := dns_settings["dns_servers"]; v != nil {
dns_servers := dns_settings["dns_servers"].([]interface{})
if len(dns_servers) > 0 {
var dnsServers []string
for _, v := range dns_servers {
str := v.(string)
dnsServers = append(dnsServers, str)
}
dnsSettings.DNSServers = &dnsServers
}
}
}
ipConfigurationConfigs := config["ip_configuration"].([]interface{})
ipConfigurations := make([]compute.VirtualMachineScaleSetIPConfiguration, 0, len(ipConfigurationConfigs))
for _, ipConfigConfig := range ipConfigurationConfigs {
Expand Down Expand Up @@ -1486,6 +1541,8 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *
Primary: &primary,
IPConfigurations: &ipConfigurations,
EnableAcceleratedNetworking: &acceleratedNetworking,
EnableIPForwarding: &ipForwarding,
DNSSettings: &dnsSettings,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we only set DNSSettings to an object when dns_servers is populated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will check if this is easily doable, but from the look of it, all other optional settings are always set: e.g. primary, acceleratedNetworking, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally we don't as some API's will break when empty objects are sent, its more a proactive choice to minimize that chance. It is easy enough by just creating the object above, and then only setting the field if required. However if the API is ok with an empty DNSSettings object then its not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested and the API support it , for now I left it the same.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

},
}

Expand Down
Loading