Skip to content

Commit

Permalink
fixing test to work with TypeSet and converting dns_settings to TypeList
Browse files Browse the repository at this point in the history
  • Loading branch information
djsly committed May 29, 2018
1 parent 40b157c commit abe552c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
},

"dns_settings": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down Expand Up @@ -1050,16 +1050,16 @@ func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.Virtual
}

if netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.DNSSettings != nil {
dnsSettings := make(map[string]interface{})
dnsServers := make([]interface{}, 0)
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)
}
dnsSettings["dns_servers"] = dnsServers
dnsSetting["dns_servers"] = dnsServers
}

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

if netConfig.VirtualMachineScaleSetNetworkConfigurationProperties.IPConfigurations != nil {
Expand Down Expand Up @@ -1418,7 +1418,7 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *
acceleratedNetworking := config["accelerated_networking"].(bool)
ipForwarding := config["ip_forwarding"].(bool)

dnsSettingsConfigs := config["dns_settings"].(*schema.Set).List()
dnsSettingsConfigs := config["dns_settings"].([]interface{})
dnsSettings := compute.VirtualMachineScaleSetNetworkConfigurationDNSSettings{}
for _, dnsSettingsConfig := range dnsSettingsConfigs {
dns_settings := dnsSettingsConfig.(map[string]interface{})
Expand Down
13 changes: 9 additions & 4 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) {
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
// testing default scaleset values
testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(resourceName, true),
resource.TestCheckResourceAttr(resourceName, "ip_forwarding", "false"),
),
},
},
Expand Down Expand Up @@ -78,6 +77,9 @@ func TestAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(t *testing.
func TestAccAzureRMVirtualMachineScaleSet_basicIPForwarding(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := acctest.RandInt()
networkProfileName := fmt.Sprintf("TestNetworkProfile-%d", ri)
networkProfile := map[string]interface{}{"name": networkProfileName, "primary": true}
networkProfileHash := fmt.Sprintf("%d", resourceArmVirtualMachineScaleSetNetworkConfigurationHash(networkProfile))
config := testAccAzureRMVirtualMachineScaleSet_basicIPForwarding(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -88,7 +90,7 @@ func TestAccAzureRMVirtualMachineScaleSet_basicIPForwarding(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "ip_forwarding", "true"),
resource.TestCheckResourceAttr(resourceName, "network_profile."+networkProfileHash+".ip_forwarding", "true"),
),
},
},
Expand All @@ -98,6 +100,9 @@ func TestAccAzureRMVirtualMachineScaleSet_basicIPForwarding(t *testing.T) {
func TestAccAzureRMVirtualMachineScaleSet_basicDNSSettings(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := acctest.RandInt()
networkProfileName := fmt.Sprintf("TestNetworkProfile-%d", ri)
networkProfile := map[string]interface{}{"name": networkProfileName, "primary": true}
networkProfileHash := fmt.Sprintf("%d", resourceArmVirtualMachineScaleSetNetworkConfigurationHash(networkProfile))
config := testAccAzureRMVirtualMachineScaleSet_basicDNSSettings(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -108,8 +113,8 @@ func TestAccAzureRMVirtualMachineScaleSet_basicDNSSettings(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "dns_settings.0.dns_servers.0", "8.8.8.8"),
resource.TestCheckResourceAttr(resourceName, "dns_settings.0.dns_servers.1", "8.8.4.4"),
resource.TestCheckResourceAttr(resourceName, "network_profile."+networkProfileHash+".dns_settings.0.dns_servers.0", "8.8.8.8"),
resource.TestCheckResourceAttr(resourceName, "network_profile."+networkProfileHash+".dns_settings.0.dns_servers.1", "8.8.4.4"),
),
},
},
Expand Down

0 comments on commit abe552c

Please sign in to comment.