Skip to content

Commit

Permalink
Merge pull request #128 from thiagocaiubi/fix-import-nic-public-ip
Browse files Browse the repository at this point in the history
Fix import of public ip of a network interface
  • Loading branch information
tombuildsstuff authored Jun 26, 2017
2 parents b319747 + 6a9e388 commit 1736bbb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
22 changes: 22 additions & 0 deletions azurerm/import_arm_network_interface_card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
}
2 changes: 1 addition & 1 deletion azurerm/resource_arm_network_interface_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
43 changes: 43 additions & 0 deletions azurerm/resource_arm_network_interface_card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 1736bbb

Please sign in to comment.