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

provider/azurerm: fix network_interface.ip_configuration hash for load balancers #10834

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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)
}