Skip to content

Commit

Permalink
Merge pull request #6624 from neil-yechenwei/fix_nic
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops authored May 6, 2020
2 parents ad5bedf + dfd926d commit c441e85
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,29 @@ func resourceArmNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{})
Location: utils.String(location),
InterfacePropertiesFormat: &network.InterfacePropertiesFormat{
EnableAcceleratedNetworking: utils.Bool(d.Get("enable_accelerated_networking").(bool)),
DNSSettings: &network.InterfaceDNSSettings{},
},
}

if d.HasChange("dns_servers") {
if update.InterfacePropertiesFormat.DNSSettings == nil {
update.InterfacePropertiesFormat.DNSSettings = &network.InterfaceDNSSettings{}
}

dnsServersRaw := d.Get("dns_servers").([]interface{})
dnsServers := expandNetworkInterfaceDnsServers(dnsServersRaw)

update.InterfacePropertiesFormat.DNSSettings.DNSServers = &dnsServers
} else {
update.InterfacePropertiesFormat.DNSSettings.DNSServers = existing.InterfacePropertiesFormat.DNSSettings.DNSServers
}

if d.HasChange("enable_ip_forwarding") {
update.InterfacePropertiesFormat.EnableIPForwarding = utils.Bool(d.Get("enable_ip_forwarding").(bool))
} else {
update.InterfacePropertiesFormat.EnableIPForwarding = existing.InterfacePropertiesFormat.EnableIPForwarding
}

if d.HasChange("internal_dns_name_label") {
if update.InterfacePropertiesFormat.DNSSettings == nil {
update.InterfacePropertiesFormat.DNSSettings = &network.InterfaceDNSSettings{}
}

update.InterfacePropertiesFormat.DNSSettings.InternalDNSNameLabel = utils.String(d.Get("internal_dns_name_label").(string))
} else {
update.InterfacePropertiesFormat.DNSSettings.InternalDNSNameLabel = existing.InterfacePropertiesFormat.DNSSettings.InternalDNSNameLabel
}

if d.HasChange("ip_configuration") {
Expand Down Expand Up @@ -364,6 +363,8 @@ func resourceArmNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{})
if d.HasChange("tags") {
tagsRaw := d.Get("tags").(map[string]interface{})
update.Tags = tags.Expand(tagsRaw)
} else {
update.Tags = existing.Tags
}

// this can be managed in another resource, so just port it over
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,31 @@ func TestAccAzureRMNetworkInterface_update(t *testing.T) {
})
}

func TestAccAzureRMNetworkInterface_updateMultipleParameters(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_network_interface", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkInterface_withMultipleParameters(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMNetworkInterface_updateMultipleParameters(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMNetworkInterfaceExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient
Expand Down Expand Up @@ -444,6 +469,66 @@ resource "azurerm_network_interface" "test" {
`, template, data.RandomInteger)
}

func testAccAzureRMNetworkInterface_withMultipleParameters(data acceptance.TestData) string {
template := testAccAzureRMNetworkInterface_template(data)
return fmt.Sprintf(`
%s
resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
enable_ip_forwarding = true
internal_dns_name_label = "acctestni-%s"
dns_servers = [
"10.0.0.5",
"10.0.0.6"
]
ip_configuration {
name = "primary"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
}
tags = {
env = "Test"
}
}
`, template, data.RandomInteger, data.RandomString)
}

func testAccAzureRMNetworkInterface_updateMultipleParameters(data acceptance.TestData) string {
template := testAccAzureRMNetworkInterface_template(data)
return fmt.Sprintf(`
%s
resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
enable_ip_forwarding = true
internal_dns_name_label = "acctestni-%s"
dns_servers = [
"10.0.0.5",
"10.0.0.7"
]
ip_configuration {
name = "primary"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
}
tags = {
env = "Test2"
}
}
`, template, data.RandomInteger, data.RandomString)
}

func testAccAzureRMNetworkInterface_dnsServers(data acceptance.TestData) string {
template := testAccAzureRMNetworkInterface_template(data)
return fmt.Sprintf(`
Expand Down

0 comments on commit c441e85

Please sign in to comment.