From c4af9ffd13ac0df34067f9267a44756138bba537 Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Thu, 24 Oct 2024 17:55:17 +0800 Subject: [PATCH 1/4] support new property domain_name_label_scope --- .../services/network/public_ip_resource.go | 28 ++++++++++++++++++- .../network/public_ip_resource_test.go | 1 + website/docs/r/public_ip.html.markdown | 4 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/internal/services/network/public_ip_resource.go b/internal/services/network/public_ip_resource.go index f8f5ebb60d30..c755834f289b 100644 --- a/internal/services/network/public_ip_resource.go +++ b/internal/services/network/public_ip_resource.go @@ -4,6 +4,7 @@ package network import ( + "context" "fmt" "log" "strings" @@ -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, @@ -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) != "") + }), + ), } } @@ -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 { @@ -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 } @@ -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{} @@ -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) diff --git a/internal/services/network/public_ip_resource_test.go b/internal/services/network/public_ip_resource_test.go index 20f9174395ad..bb598cfbb659 100644 --- a/internal/services/network/public_ip_resource_test.go +++ b/internal/services/network/public_ip_resource_test.go @@ -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) diff --git a/website/docs/r/public_ip.html.markdown b/website/docs/r/public_ip.html.markdown index 1f4eccb6dec5..4c8a9d46f17f 100644 --- a/website/docs/r/public_ip.html.markdown +++ b/website/docs/r/public_ip.html.markdown @@ -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. + * `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. From 0f1313ef70247a7bceddcab1868860e6b8758296 Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Fri, 25 Oct 2024 10:06:57 +0800 Subject: [PATCH 2/4] fix comments --- internal/services/network/public_ip_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/network/public_ip_resource_test.go b/internal/services/network/public_ip_resource_test.go index bb598cfbb659..e28974083c84 100644 --- a/internal/services/network/public_ip_resource_test.go +++ b/internal/services/network/public_ip_resource_test.go @@ -895,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)))) } func (PublicIPResource) standard_IpTags(data acceptance.TestData) string { From 68df18d03b7334afa869e3fde97d330b949195aa Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 5 Nov 2024 11:26:50 -0800 Subject: [PATCH 3/4] Update internal/services/network/public_ip_resource_test.go --- internal/services/network/public_ip_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/network/public_ip_resource_test.go b/internal/services/network/public_ip_resource_test.go index e28974083c84..527b644dd1e9 100644 --- a/internal/services/network/public_ip_resource_test.go +++ b/internal/services/network/public_ip_resource_test.go @@ -895,7 +895,7 @@ resource "azurerm_public_ip" "test" { sku = "Basic" domain_name_label = "%s" } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, fmt.Sprintf("test%s", strings.ToLower(data.RandomStringOfLength(59)))) +`, 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 { From 779d7ea001476edcff4b3cb3894ad15053894b62 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 5 Nov 2024 15:03:12 -0800 Subject: [PATCH 4/4] Update website/docs/r/public_ip.html.markdown --- website/docs/r/public_ip.html.markdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/website/docs/r/public_ip.html.markdown b/website/docs/r/public_ip.html.markdown index 4c8a9d46f17f..5abc7f89543c 100644 --- a/website/docs/r/public_ip.html.markdown +++ b/website/docs/r/public_ip.html.markdown @@ -60,9 +60,7 @@ 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. +* `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`. Changing this forces a new Public IP to be created. * `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.