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

azurerm_public_ip - support for the domain_name_label_scope property #27748

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 27 additions & 1 deletion internal/services/network/public_ip_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package network

import (
"context"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -142,6 +143,12 @@ func resourcePublicIp() *pluginsdk.Resource {
ValidateFunc: validate.PublicIpDomainNameLabel,
},

"domain_name_label_scope": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(publicipaddresses.PossibleValuesForPublicIPAddressDnsSettingsDomainNameLabelScope(), false),
},

"fqdn": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -177,6 +184,12 @@ func resourcePublicIp() *pluginsdk.Resource {

"tags": commonschema.Tags(),
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.ForceNewIfChange("domain_name_label_scope", func(ctx context.Context, old, new, meta interface{}) bool {
return !(old.(string) == "" && new.(string) != "")
}),
),
}
}

Expand Down Expand Up @@ -256,8 +269,9 @@ func resourcePublicIpCreate(d *pluginsdk.ResourceData, meta interface{}) error {

dnl, dnlOk := d.GetOk("domain_name_label")
rfqdn, rfqdnOk := d.GetOk("reverse_fqdn")
dnlc, dnlcOk := d.GetOk("domain_name_label_scope")

if dnlOk || rfqdnOk {
if dnlOk || rfqdnOk || dnlcOk {
dnsSettings := publicipaddresses.PublicIPAddressDnsSettings{}

if rfqdnOk {
Expand All @@ -268,6 +282,10 @@ func resourcePublicIpCreate(d *pluginsdk.ResourceData, meta interface{}) error {
dnsSettings.DomainNameLabel = pointer.To(dnl.(string))
}

if dnlcOk {
dnsSettings.DomainNameLabelScope = pointer.To(publicipaddresses.PublicIPAddressDnsSettingsDomainNameLabelScope(dnlc.(string)))
}

publicIp.Properties.DnsSettings = &dnsSettings
}

Expand Down Expand Up @@ -354,6 +372,13 @@ func resourcePublicIpUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
payload.Properties.DnsSettings.DomainNameLabel = utils.String(d.Get("domain_name_label").(string))
}

if d.HasChange("domain_name_label_scope") {
if payload.Properties.DnsSettings == nil {
payload.Properties.DnsSettings = &publicipaddresses.PublicIPAddressDnsSettings{}
}
payload.Properties.DnsSettings.DomainNameLabelScope = pointer.To(publicipaddresses.PublicIPAddressDnsSettingsDomainNameLabelScope(d.Get("domain_name_label_scope").(string)))
}

if d.HasChange("reverse_fqdn") {
if payload.Properties.DnsSettings == nil {
payload.Properties.DnsSettings = &publicipaddresses.PublicIPAddressDnsSettings{}
Expand Down Expand Up @@ -416,6 +441,7 @@ func resourcePublicIpRead(d *pluginsdk.ResourceData, meta interface{}) error {
d.Set("fqdn", settings.Fqdn)
d.Set("reverse_fqdn", settings.ReverseFqdn)
d.Set("domain_name_label", settings.DomainNameLabel)
d.Set("domain_name_label_scope", string(pointer.From(settings.DomainNameLabelScope)))
}

ddosProtectionMode := string(publicipaddresses.DdosSettingsProtectionModeVirtualNetworkInherited)
Expand Down
3 changes: 2 additions & 1 deletion internal/services/network/public_ip_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ resource "azurerm_public_ip" "test" {
allocation_method = "Static"
sku = "Basic"
domain_name_label = "acctest-%d"
domain_name_label_scope = "TenantReuse"
idle_timeout_in_minutes = 30
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
Expand Down Expand Up @@ -894,7 +895,7 @@ resource "azurerm_public_ip" "test" {
sku = "Basic"
domain_name_label = "%s"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, strings.ToLower(data.RandomStringOfLength(63)))
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, fmt.Sprintf("test%s", strings.ToLower(data.RandomStringOfLength(59)))) // prepend with test (4+59) to ensure the string starts with a letter
}

func (PublicIPResource) standard_IpTags(data acceptance.TestData) string {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/public_ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ The following arguments are supported:

* `domain_name_label` - (Optional) Label for the Domain Name. Will be used to make up the FQDN. If a domain name label is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system.

* `domain_name_label_scope` - (Optional) Scope for the domain name label. If a domain name label scope is specified, an A DNS record is created for the public IP in the Microsoft Azure DNS system with a hashed value includes in FQDN. Possible values are `NoReuse`, `ResourceGroupReuse`, `SubscriptionReuse` and `TenantReuse`.

-> **Note** Once `domain_name_label_scope` is specified, it cannot be changed, changing it forces a new resource to be created.
katbyte marked this conversation as resolved.
Show resolved Hide resolved

* `edge_zone` - (Optional) Specifies the Edge Zone within the Azure Region where this Public IP should exist. Changing this forces a new Public IP to be created.

* `idle_timeout_in_minutes` - (Optional) Specifies the timeout for the TCP idle connection. The value can be set between 4 and 30 minutes.
Expand Down
Loading