From 243000fc85f3f161ff1f05bff51ff0deaed0d7eb Mon Sep 17 00:00:00 2001 From: Peter McAtominey Date: Mon, 19 Dec 2016 12:32:08 +0000 Subject: [PATCH] provider/azurerm: fix network_interface.ip_configuration has for load balancers The subsets for backend address pools and inbound nat rules weren't being hashed properly as part of the ip_configuration hash which caused multiple ip_configurations to be expanded and sent to the API with conflicting names TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMNetworkInterface -timeout 120m === RUN TestAccAzureRMNetworkInterface_basic --- PASS: TestAccAzureRMNetworkInterface_basic (160.24s) === RUN TestAccAzureRMNetworkInterface_disappears --- PASS: TestAccAzureRMNetworkInterface_disappears (157.00s) === RUN TestAccAzureRMNetworkInterface_enableIPForwarding --- PASS: TestAccAzureRMNetworkInterface_enableIPForwarding (156.86s) === RUN TestAccAzureRMNetworkInterface_multipleLoadBalancers --- PASS: TestAccAzureRMNetworkInterface_multipleLoadBalancers (185.87s) === RUN TestAccAzureRMNetworkInterface_withTags --- PASS: TestAccAzureRMNetworkInterface_withTags (1212.92s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 1872.960s --- .../resource_arm_network_interface_card.go | 10 +- ...esource_arm_network_interface_card_test.go | 148 ++++++++++++++++++ 2 files changed, 156 insertions(+), 2 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_network_interface_card.go b/builtin/providers/azurerm/resource_arm_network_interface_card.go index e48b5f182275..9cdccac185f9 100644 --- a/builtin/providers/azurerm/resource_arm_network_interface_card.go +++ b/builtin/providers/azurerm/resource_arm_network_interface_card.go @@ -324,10 +324,16 @@ func resourceArmNetworkInterfaceIpConfigurationHash(v interface{}) int { buf.WriteString(fmt.Sprintf("%s-", m["public_ip_address_id"].(string))) } if m["load_balancer_backend_address_pools_ids"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["load_balancer_backend_address_pools_ids"].(*schema.Set).GoString())) + ids := m["load_balancer_backend_address_pools_ids"].(*schema.Set).List() + for _, id := range ids { + buf.WriteString(fmt.Sprintf("%d-", schema.HashString(id.(string)))) + } } if m["load_balancer_inbound_nat_rules_ids"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["load_balancer_inbound_nat_rules_ids"].(*schema.Set).GoString())) + ids := m["load_balancer_inbound_nat_rules_ids"].(*schema.Set).List() + for _, id := range ids { + buf.WriteString(fmt.Sprintf("%d-", schema.HashString(id.(string)))) + } } return hashcode.String(buf.String()) diff --git a/builtin/providers/azurerm/resource_arm_network_interface_card_test.go b/builtin/providers/azurerm/resource_arm_network_interface_card_test.go index 003673791aad..f967759805e0 100644 --- a/builtin/providers/azurerm/resource_arm_network_interface_card_test.go +++ b/builtin/providers/azurerm/resource_arm_network_interface_card_test.go @@ -65,6 +65,24 @@ func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) { }) } +func TestAccAzureRMNetworkInterface_multipleLoadBalancers(t *testing.T) { + rInt := acctest.RandInt() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterface_multipleLoadBalancers(rInt), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test1"), + testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test2"), + ), + }, + }, + }) +} + func TestAccAzureRMNetworkInterface_withTags(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ @@ -326,3 +344,133 @@ resource "azurerm_network_interface" "test" { } `, rInt) } + +func testAccAzureRMNetworkInterface_multipleLoadBalancers(rInt int) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%d" + location = "West US" +} + +resource "azurerm_virtual_network" "test" { + name = "acceptanceTestVirtualNetwork1" + address_space = ["10.0.0.0/16"] + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "testsubnet" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_public_ip" "testext" { + name = "testpublicipext" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurerm_lb" "testext" { + name = "testlbext" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + + frontend_ip_configuration { + name = "publicipext" + public_ip_address_id = "${azurerm_public_ip.testext.id}" + } +} + +resource "azurerm_lb_backend_address_pool" "testext" { + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + loadbalancer_id = "${azurerm_lb.testext.id}" + name = "testbackendpoolext" +} + +resource "azurerm_lb_nat_rule" "testext" { + name = "testnatruleext" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + loadbalancer_id = "${azurerm_lb.testext.id}" + protocol = "Tcp" + frontend_port = 3389 + backend_port = 3390 + frontend_ip_configuration_name = "publicipext" +} + +resource "azurerm_public_ip" "testint" { + name = "testpublicipint" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurerm_lb" "testint" { + name = "testlbint" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + + frontend_ip_configuration { + name = "publicipint" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_lb_backend_address_pool" "testint" { + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + loadbalancer_id = "${azurerm_lb.testint.id}" + name = "testbackendpoolint" +} + +resource "azurerm_lb_nat_rule" "testint" { + name = "testnatruleint" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + loadbalancer_id = "${azurerm_lb.testint.id}" + protocol = "Tcp" + frontend_port = 3389 + backend_port = 3391 + frontend_ip_configuration_name = "publicipint" +} + +resource "azurerm_network_interface" "test1" { + name = "acceptanceTestNetworkInterface1" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + enable_ip_forwarding = true + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + load_balancer_backend_address_pools_ids = [ + "${azurerm_lb_backend_address_pool.testext.id}", + "${azurerm_lb_backend_address_pool.testint.id}", + ] + } +} + +resource "azurerm_network_interface" "test2" { + name = "acceptanceTestNetworkInterface2" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + enable_ip_forwarding = true + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + load_balancer_inbound_nat_rules_ids = [ + "${azurerm_lb_nat_rule.testext.id}", + "${azurerm_lb_nat_rule.testint.id}", + ] + } +} +`, rInt) +}