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": { diff --git a/azurerm/resource_arm_network_interface_test.go b/azurerm/resource_arm_network_interface_test.go index 91c52b95d067..362b5f4c22c9 100644 --- a/azurerm/resource_arm_network_interface_test.go +++ b/azurerm/resource_arm_network_interface_test.go @@ -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{ @@ -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" {