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

Fix update scenario for network interface #6624

Merged
merged 22 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a16d4db
Fix update scenario for network interface
Apr 23, 2020
03c8e92
Merge remote-tracking branch 'upstream/master' into fix_nic
Apr 23, 2020
0076714
provider: update terrafmt checks with make terrafmt command (#6567)
katbyte Apr 22, 2020
fbb8ed0
provider: pin golangci to 1.24 (#6577)
katbyte Apr 22, 2020
7a306d2
provider tests: removes the requires import feature flag [L-W] (#6573)
tracypholmes Apr 22, 2020
df1abaf
`azurerm_function_app` - Added `storage_account_id` and `storage_acco…
mbfrahry Apr 22, 2020
418c381
update for #6304
mbfrahry Apr 22, 2020
134823a
`azurerm_iothub_dps` - fix crash when path isn't cased correctly #6570
mbfrahry Apr 22, 2020
06ed60a
Update for #6570
mbfrahry Apr 22, 2020
1b52ecf
`azurerm_linux_virtual_machine_scale_set` - fixes crash with `boot_di…
mbfrahry Apr 22, 2020
60f23e0
Update for #6569
mbfrahry Apr 22, 2020
8786915
provider: upgrade API Management to 2019-12-01 (#6479)
katbyte Apr 22, 2020
1da7541
update CHANGELOG.md to include #6479
katbyte Apr 22, 2020
b0d2780
`azurerm_private_endpoint`: Add support for tags (#6574)
Apr 23, 2020
1e55c70
`azurerm_public_ip_prefix`: Update `prefix_length` validation to acce…
WodansSon Apr 23, 2020
44b223e
updating to include #6574 and #6589
WodansSon Apr 23, 2020
4223b99
Updating instead of foo to example (#6591)
Rituraj12345 Apr 23, 2020
66f67d4
Revert "CDN Endpoint: make origin_host_header required " (#6583)
mbfrahry Apr 23, 2020
538f7b1
...
Apr 24, 2020
ac23ac7
...
Apr 24, 2020
80b656e
Merge branch 'fix_nic' of https://github.com/microsoft/terraform-prov…
Apr 24, 2020
dfd926d
Update code
May 6, 2020
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
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.6"
]
Copy link
Member

Choose a reason for hiding this comment

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

The linked issue refers to changing DNS servers, but these stay the same through the update test, should we be testing/validating this in the update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


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