Skip to content

Commit

Permalink
Merge pull request hashicorp#1287 from shanepoint/Public_ip-Domain_na…
Browse files Browse the repository at this point in the history
…me_label-fix

Added domain_name_label to read to fix import. (hashicorp#784)
  • Loading branch information
katbyte authored May 25, 2018
2 parents 179b3c0 + 2b845d4 commit 1e9c8c2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
24 changes: 24 additions & 0 deletions azurerm/import_arm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ func TestAccAzureRMPublicIpStatic_importBasic_withZone(t *testing.T) {
})
}

func TestAccAzureRMPublicIpStatic_importBasic_withDNSLabel(t *testing.T) {
resourceName := "azurerm_public_ip.test"

ri := acctest.RandInt()
dnl := fmt.Sprintf("acctestdnl-%d", ri)
config := testAccAzureRMPublicIPStatic_basic_withDNSLabel(ri, testLocation(), dnl)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPublicIpDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMPublicIpStatic_importIdError(t *testing.T) {
resourceName := "azurerm_public_ip.test"

Expand Down
16 changes: 9 additions & 7 deletions azurerm/resource_arm_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func resourceArmPublicIp() *schema.Resource {

"zones": singleZonesSchema(),

//should this perhaps be allocation_method?
"public_ip_address_allocation": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -128,18 +129,18 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
PublicIPAllocationMethod: ipAllocationMethod,
}

dnl, hasDnl := d.GetOk("domain_name_label")
rfqdn, hasRfqdn := d.GetOk("reverse_fqdn")
dnl, dnlOk := d.GetOk("domain_name_label")
rfqdn, rfqdnOk := d.GetOk("reverse_fqdn")

if hasDnl || hasRfqdn {
if dnlOk || rfqdnOk {
dnsSettings := network.PublicIPAddressDNSSettings{}

if hasRfqdn {
if rfqdnOk {
reverseFqdn := rfqdn.(string)
dnsSettings.ReverseFqdn = &reverseFqdn
}

if hasDnl {
if dnlOk {
domainNameLabel := dnl.(string)
dnsSettings.DomainNameLabel = &domainNameLabel
}
Expand All @@ -148,8 +149,7 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
}

if v, ok := d.GetOk("idle_timeout_in_minutes"); ok {
idleTimeout := int32(v.(int))
properties.IdleTimeoutInMinutes = &idleTimeout
properties.IdleTimeoutInMinutes = utils.Int32(int32(v.(int)))
}

publicIp := network.PublicIPAddress{
Expand Down Expand Up @@ -227,6 +227,8 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
} else {
d.Set("fqdn", "")
}

d.Set("domain_name_label", settings.DomainNameLabel)
}

if ip := props.IPAddress; ip != nil {
Expand Down
58 changes: 51 additions & 7 deletions azurerm/resource_arm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ func TestAccAzureRMPublicIpStatic_basic(t *testing.T) {
})
}

func TestAccAzureRMPublicIpStatic_basic_withDNSLabel(t *testing.T) {
resourceName := "azurerm_public_ip.test"
ri := acctest.RandInt()
dnl := fmt.Sprintf("acctestdnl-%d", ri)
config := testAccAzureRMPublicIPStatic_basic_withDNSLabel(ri, testLocation(), dnl)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPublicIpDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPublicIpExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "ip_address"),
resource.TestCheckResourceAttr(resourceName, "public_ip_address_allocation", "static"),
resource.TestCheckResourceAttr(resourceName, "domain_name_label", dnl),
),
},
},
})
}

func TestAccAzureRMPublicIpStatic_standard(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMPublicIPStatic_standard(ri, testLocation())
Expand Down Expand Up @@ -296,14 +320,15 @@ func testCheckAzureRMPublicIpDestroy(s *terraform.State) error {
func testAccAzureRMPublicIPStatic_basic(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
}
`, rInt, location, rInt)
Expand All @@ -312,20 +337,39 @@ resource "azurerm_public_ip" "test" {
func testAccAzureRMPublicIPStatic_basic_withZone(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
zones = ["1"]
}
`, rInt, location, rInt)
}

func testAccAzureRMPublicIPStatic_basic_withDNSLabel(rInt int, location, dnsNameLabel string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
domain_name_label = "%s"
}
`, rInt, location, rInt, dnsNameLabel)
}

func testAccAzureRMPublicIPStatic_standard(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit 1e9c8c2

Please sign in to comment.