provider/azurerm: fix network_interface.ip_configuration has for load 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
This commit is contained in:
Peter McAtominey 2016-12-19 13:21:51 +00:00 committed by Paul Stack
parent 504407c1cb
commit b4e0b8a9f5
2 changed files with 156 additions and 2 deletions

View File

@ -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())

View File

@ -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)
}