Skip to content

Commit

Permalink
Fixing issue 1286 : We are unable to disassociate a PIP once attached (
Browse files Browse the repository at this point in the history
…#1295)

* Fixing issue 1286 : We are unable to disassociate a PIP once attached because of this

* Added the test case for Bug 1286

* Ensuring the fields are reset to nothing
  • Loading branch information
VaijanathB authored and tombuildsstuff committed Jun 1, 2018
1 parent aab882f commit 5a91175
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
2 changes: 0 additions & 2 deletions azurerm/resource_arm_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func resourceArmNetworkInterface() *schema.Resource {
"private_ip_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"private_ip_address_allocation": {
Expand All @@ -85,7 +84,6 @@ func resourceArmNetworkInterface() *schema.Resource {
"public_ip_address_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"application_gateway_backend_address_pools_ids": {
Expand Down
116 changes: 116 additions & 0 deletions azurerm/resource_arm_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,34 @@ func TestAccAzureRMNetworkInterface_withTags(t *testing.T) {
})
}

func TestAccAzureRMNetworkInterface_IPAddressesBug1286(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkInterface_withIPAddresses(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"),
resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.public_ip_address_id"),
),
},
{
Config: testAccAzureRMNetworkInterface_withIPAddressesUpdate(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.private_ip_address", ""),
resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.public_ip_address_id", ""),
),
},
},
})
}

func TestAccAzureRMNetworkInterface_bug7986(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -790,6 +818,94 @@ resource "azurerm_network_interface" "test" {
`, rInt, location, rInt, rInt)
}

func testAccAzureRMNetworkInterface_withIPAddresses(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctest-rg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
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" "test" {
name = "test-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
domain_name_label = "${azurerm_resource_group.test.name}"
}
resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "static"
private_ip_address = "10.0.2.9"
public_ip_address_id = "${azurerm_public_ip.test.id}"
}
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMNetworkInterface_withIPAddressesUpdate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctest-rg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
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" "test" {
name = "test-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
domain_name_label = "${azurerm_resource_group.test.name}"
}
resource "azurerm_network_interface" "test" {
name = "acctestni-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMNetworkInterface_multipleLoadBalancers(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit 5a91175

Please sign in to comment.