Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added domain_name_label to read to fix import. (#784) #1287

Merged
merged 5 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd kind of agree with this, but I don't think it's one for this PR.

It's worth noting that IPv4 and IPv6 will both be supported here at some point in the future (the SDK supports it today, but the underlying Azure infra didn't last time I tried it) - so it may make sense to rename/differentiate them at that point.

"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