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

Fixing issue 1286 : We are unable to disassociate a PIP once attached #1295

Merged
merged 5 commits into from
Jun 1, 2018
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
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also verify these are set to nothing (e.g. there's no Public/Private IP Addresses set) via:

resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.private_ip_address", ""),
resource.TestCheckResourceAttr(resourceName, "ip_configuration.0. public_ip_address_id", ""),

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