diff --git a/azurerm/import_arm_network_interface_card_test.go b/azurerm/import_arm_network_interface_card_test.go index 3bb4806e0c4b..459b2e96a40d 100644 --- a/azurerm/import_arm_network_interface_card_test.go +++ b/azurerm/import_arm_network_interface_card_test.go @@ -94,3 +94,25 @@ func TestAccAzureRMNetworkInterface_importMultipleLoadBalancers(t *testing.T) { }, }) } + +func TestAccAzureRMNetworkInterface_importPublicIP(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{ + resource.TestStep{ + Config: testAccAzureRMNetworkInterface_publicIP(rInt), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/azurerm/resource_arm_network_interface_card.go b/azurerm/resource_arm_network_interface_card.go index 19c6dad5ab15..64543eebb10f 100644 --- a/azurerm/resource_arm_network_interface_card.go +++ b/azurerm/resource_arm_network_interface_card.go @@ -442,7 +442,7 @@ func flattenNetworkInterfaceIPConfigurations(ipConfigs *[]network.InterfaceIPCon } if ipConfig.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress != nil { - niIPConfig["public_ip_address_id"] = ipConfig.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.ID + niIPConfig["public_ip_address_id"] = *ipConfig.InterfaceIPConfigurationPropertiesFormat.PublicIPAddress.ID } var pools []interface{} diff --git a/azurerm/resource_arm_network_interface_card_test.go b/azurerm/resource_arm_network_interface_card_test.go index 99af7f1ee54c..2043d481845a 100644 --- a/azurerm/resource_arm_network_interface_card_test.go +++ b/azurerm/resource_arm_network_interface_card_test.go @@ -597,3 +597,46 @@ resource "azurerm_network_interface" "test2" { } `, rInt, rInt, rInt, rInt, rInt, rInt) } + +func testAccAzureRMNetworkInterface_publicIP(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_network_interface" "test" { + name = "acceptanceTestNetworkInterface1" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + public_ip_address_id = "${azurerm_public_ip.testext.id}" + } +} +`, rInt) +}