diff --git a/azurerm/internal/services/network/resource_arm_network_interface.go b/azurerm/internal/services/network/resource_arm_network_interface.go index 2f841fe66821..111e745fcb69 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface.go +++ b/azurerm/internal/services/network/resource_arm_network_interface.go @@ -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") { @@ -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 diff --git a/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go index d3c5ba303696..16811129fcc7 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go @@ -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 @@ -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(`