From 4b1a0e209b5393a377f1b1145bc42d29a380c10d Mon Sep 17 00:00:00 2001 From: Vaijanath Angadihiremath Date: Thu, 24 May 2018 20:21:44 +0000 Subject: [PATCH 1/3] Fixing issue 1286 : We are unable to disassociate a PIP once attached because of this --- azurerm/resource_arm_network_interface.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/azurerm/resource_arm_network_interface.go b/azurerm/resource_arm_network_interface.go index 8e58696425b7..d4ab01c1f20d 100644 --- a/azurerm/resource_arm_network_interface.go +++ b/azurerm/resource_arm_network_interface.go @@ -68,7 +68,6 @@ func resourceArmNetworkInterface() *schema.Resource { "private_ip_address": { Type: schema.TypeString, Optional: true, - Computed: true, }, "private_ip_address_allocation": { @@ -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": { From f8fc29e06b711e3f63fd1dcc0ba56b45251dba06 Mon Sep 17 00:00:00 2001 From: Vaijanath Angadihiremath Date: Tue, 29 May 2018 22:43:39 +0000 Subject: [PATCH 2/3] Added the test case for Bug 1286 --- .../resource_arm_network_interface_test.go | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/azurerm/resource_arm_network_interface_test.go b/azurerm/resource_arm_network_interface_test.go index 91c52b95d067..f9f19ac49238 100644 --- a/azurerm/resource_arm_network_interface_test.go +++ b/azurerm/resource_arm_network_interface_test.go @@ -333,6 +333,32 @@ 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), + ), + }, + }, + }) +} + func TestAccAzureRMNetworkInterface_bug7986(t *testing.T) { rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ @@ -790,6 +816,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" { From 473b461961b0218cd9bc072db21da3af9711f708 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 1 Jun 2018 12:18:24 +0200 Subject: [PATCH 3/3] Ensuring the fields are reset to nothing --- azurerm/resource_arm_network_interface_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azurerm/resource_arm_network_interface_test.go b/azurerm/resource_arm_network_interface_test.go index f9f19ac49238..362b5f4c22c9 100644 --- a/azurerm/resource_arm_network_interface_test.go +++ b/azurerm/resource_arm_network_interface_test.go @@ -353,6 +353,8 @@ func TestAccAzureRMNetworkInterface_IPAddressesBug1286(t *testing.T) { 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", ""), ), }, },