Skip to content

Commit

Permalink
provider/azurerm: fix network_interface.ip_configuration has for load…
Browse files Browse the repository at this point in the history
… balancers (#10834)

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
  • Loading branch information
pmcatominey authored and stack72 committed Dec 19, 2016
1 parent 504407c commit b4e0b8a
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 2 deletions.
10 changes: 8 additions & 2 deletions builtin/providers/azurerm/resource_arm_network_interface_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
148 changes: 148 additions & 0 deletions builtin/providers/azurerm/resource_arm_network_interface_card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

0 comments on commit b4e0b8a

Please sign in to comment.