From 99e4233353f6c112c794118e2ab5d4e8188c6dd0 Mon Sep 17 00:00:00 2001 From: Szasza Palmer Date: Sat, 9 Mar 2024 18:53:49 +1100 Subject: [PATCH 1/8] aws_route53domains_registered_domain: Add billing_contact and billing_privacy --- .../route53domains/registered_domain.go | 52 ++++++++++--- .../route53domains/registered_domain_test.go | 73 +++++++++++++++++-- 2 files changed, 107 insertions(+), 18 deletions(-) diff --git a/internal/service/route53domains/registered_domain.go b/internal/service/route53domains/registered_domain.go index dac6a64835f..3da20c57724 100644 --- a/internal/service/route53domains/registered_domain.go +++ b/internal/service/route53domains/registered_domain.go @@ -161,6 +161,12 @@ func ResourceRegisteredDomain() *schema.Resource { Optional: true, Default: true, }, + "billing_contact": contactSchema, + "billing_privacy": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, "creation_date": { Type: schema.TypeString, Computed: true, @@ -263,7 +269,7 @@ func resourceRegisteredDomainCreate(ctx context.Context, d *schema.ResourceData, d.SetId(aws.ToString(domainDetail.DomainName)) - var adminContact, registrantContact, techContact *types.ContactDetail + var adminContact, billingContact, registrantContact, techContact *types.ContactDetail if v, ok := d.GetOk("admin_contact"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { if v := expandContactDetail(v.([]interface{})[0].(map[string]interface{})); !reflect.DeepEqual(v, domainDetail.AdminContact) { @@ -271,6 +277,12 @@ func resourceRegisteredDomainCreate(ctx context.Context, d *schema.ResourceData, } } + if v, ok := d.GetOk("billing_contact"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + if v := expandContactDetail(v.([]interface{})[0].(map[string]interface{})); !reflect.DeepEqual(v, domainDetail.BillingContact) { + billingContact = v + } + } + if v, ok := d.GetOk("registrant_contact"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { if v := expandContactDetail(v.([]interface{})[0].(map[string]interface{})); !reflect.DeepEqual(v, domainDetail.RegistrantContact) { registrantContact = v @@ -283,14 +295,14 @@ func resourceRegisteredDomainCreate(ctx context.Context, d *schema.ResourceData, } } - if adminContact != nil || registrantContact != nil || techContact != nil { - if err := modifyDomainContact(ctx, conn, d.Id(), adminContact, registrantContact, techContact, d.Timeout(schema.TimeoutCreate)); err != nil { + if adminContact != nil || billingContact != nil || registrantContact != nil || techContact != nil { + if err := modifyDomainContact(ctx, conn, d.Id(), adminContact, billingContact, registrantContact, techContact, d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendFromErr(diags, err) } } - if adminPrivacy, registrantPrivacy, techPrivacy := d.Get("admin_privacy").(bool), d.Get("registrant_privacy").(bool), d.Get("tech_privacy").(bool); adminPrivacy != aws.ToBool(domainDetail.AdminPrivacy) || registrantPrivacy != aws.ToBool(domainDetail.RegistrantPrivacy) || techPrivacy != aws.ToBool(domainDetail.TechPrivacy) { - if err := modifyDomainContactPrivacy(ctx, conn, d.Id(), adminPrivacy, registrantPrivacy, techPrivacy, d.Timeout(schema.TimeoutCreate)); err != nil { + if adminPrivacy, billingPrivacy, registrantPrivacy, techPrivacy := d.Get("admin_privacy").(bool), d.Get("billing_privacy").(bool), d.Get("registrant_privacy").(bool), d.Get("tech_privacy").(bool); adminPrivacy != aws.ToBool(domainDetail.AdminPrivacy) || billingPrivacy != aws.ToBool(domainDetail.BillingPrivacy) || registrantPrivacy != aws.ToBool(domainDetail.RegistrantPrivacy) || techPrivacy != aws.ToBool(domainDetail.TechPrivacy) { + if err := modifyDomainContactPrivacy(ctx, conn, d.Id(), adminPrivacy, billingPrivacy, registrantPrivacy, techPrivacy, d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendFromErr(diags, err) } } @@ -368,6 +380,14 @@ func resourceRegisteredDomainRead(ctx context.Context, d *schema.ResourceData, m } else { d.Set("creation_date", nil) } + if domainDetail.BillingContact != nil { + if err := d.Set("billing_contact", []interface{}{flattenContactDetail(domainDetail.BillingContact)}); err != nil { + return sdkdiag.AppendErrorf(diags, "setting billing_contact: %s", err) + } + } else { + d.Set("billing_contact", nil) + } + d.Set("billing_privacy", domainDetail.BillingPrivacy) d.Set("domain_name", domainDetail.DomainName) if domainDetail.ExpirationDate != nil { d.Set("expiration_date", aws.ToTime(domainDetail.ExpirationDate).Format(time.RFC3339)) @@ -413,8 +433,8 @@ func resourceRegisteredDomainUpdate(ctx context.Context, d *schema.ResourceData, var diags diag.Diagnostics conn := meta.(*conns.AWSClient).Route53DomainsClient(ctx) - if d.HasChanges("admin_contact", "registrant_contact", "tech_contact") { - var adminContact, registrantContact, techContact *types.ContactDetail + if d.HasChanges("admin_contact", "billing_contact", "registrant_contact", "tech_contact") { + var adminContact, billingContact, registrantContact, techContact *types.ContactDetail if key := "admin_contact"; d.HasChange(key) { if v, ok := d.GetOk(key); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { @@ -422,6 +442,12 @@ func resourceRegisteredDomainUpdate(ctx context.Context, d *schema.ResourceData, } } + if key := "billing_contact"; d.HasChange(key) { + if v, ok := d.GetOk(key); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + billingContact = expandContactDetail(v.([]interface{})[0].(map[string]interface{})) + } + } + if key := "registrant_contact"; d.HasChange(key) { if v, ok := d.GetOk(key); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { registrantContact = expandContactDetail(v.([]interface{})[0].(map[string]interface{})) @@ -434,13 +460,13 @@ func resourceRegisteredDomainUpdate(ctx context.Context, d *schema.ResourceData, } } - if err := modifyDomainContact(ctx, conn, d.Id(), adminContact, registrantContact, techContact, d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := modifyDomainContact(ctx, conn, d.Id(), adminContact, billingContact, registrantContact, techContact, d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendFromErr(diags, err) } } - if d.HasChanges("admin_privacy", "registrant_privacy", "tech_privacy") { - if err := modifyDomainContactPrivacy(ctx, conn, d.Id(), d.Get("admin_privacy").(bool), d.Get("registrant_privacy").(bool), d.Get("tech_privacy").(bool), d.Timeout(schema.TimeoutUpdate)); err != nil { + if d.HasChanges("admin_privacy", "billing_contact", "registrant_privacy", "tech_privacy") { + if err := modifyDomainContactPrivacy(ctx, conn, d.Id(), d.Get("admin_privacy").(bool), d.Get("billing_privacy").(bool), d.Get("registrant_privacy").(bool), d.Get("tech_privacy").(bool), d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendFromErr(diags, err) } } @@ -501,9 +527,10 @@ func modifyDomainAutoRenew(ctx context.Context, conn *route53domains.Client, dom return nil } -func modifyDomainContact(ctx context.Context, conn *route53domains.Client, domainName string, adminContact, registrantContact, techContact *types.ContactDetail, timeout time.Duration) error { +func modifyDomainContact(ctx context.Context, conn *route53domains.Client, domainName string, adminContact, billingContact, registrantContact, techContact *types.ContactDetail, timeout time.Duration) error { input := &route53domains.UpdateDomainContactInput{ AdminContact: adminContact, + BillingContact: billingContact, DomainName: aws.String(domainName), RegistrantContact: registrantContact, TechContact: techContact, @@ -522,9 +549,10 @@ func modifyDomainContact(ctx context.Context, conn *route53domains.Client, domai return nil } -func modifyDomainContactPrivacy(ctx context.Context, conn *route53domains.Client, domainName string, adminPrivacy, registrantPrivacy, techPrivacy bool, timeout time.Duration) error { +func modifyDomainContactPrivacy(ctx context.Context, conn *route53domains.Client, domainName string, adminPrivacy, billingPrivacy, registrantPrivacy, techPrivacy bool, timeout time.Duration) error { input := &route53domains.UpdateDomainContactPrivacyInput{ AdminPrivacy: aws.Bool(adminPrivacy), + BillingPrivacy: aws.Bool(billingPrivacy), DomainName: aws.String(domainName), RegistrantPrivacy: aws.Bool(registrantPrivacy), TechPrivacy: aws.Bool(techPrivacy), diff --git a/internal/service/route53domains/registered_domain_test.go b/internal/service/route53domains/registered_domain_test.go index 0bf12cfd7a3..1c980717be6 100644 --- a/internal/service/route53domains/registered_domain_test.go +++ b/internal/service/route53domains/registered_domain_test.go @@ -108,6 +108,20 @@ func testAccRegisteredDomain_contacts(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "admin_contact.0.organization_name", "Support"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.phone_number", "+44.123456789"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.zip_code", "ST1 1AB"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.#", "1"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.address_line_1", "1 Mawson Street"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.address_line_2", "Unit 2"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.city", "Mawson"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.contact_type", "PERSON"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.country_code", "AU"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.email", "terraform-acctest+aws-route53domains-test4@hashicorp.com"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.fax", "+61.412345678"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.first_name", "John"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.last_name", "Cleese"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.organization_name", "Monty Python"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.phone_number", "+61.412345679"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.state", "ACT"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.zip_code", "2606"), resource.TestCheckResourceAttr(resourceName, "registrant_contact.#", "1"), resource.TestCheckResourceAttr(resourceName, "registrant_contact.0.address_line_1", "100 Main Street"), resource.TestCheckResourceAttr(resourceName, "registrant_contact.0.city", "New York City"), @@ -148,6 +162,19 @@ func testAccRegisteredDomain_contacts(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "admin_contact.0.phone_number", "+1.4155551234"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.state", "CA"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.zip_code", "94105"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.#", "1"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.address_line_1", "101 2nd St #700"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.city", "San Francisco"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.contact_type", "COMPANY"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.country_code", "US"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.email", "terraform-acctest+aws@hashicorp.com"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.fax", "+1.4155551234"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.first_name", "Terraform"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.last_name", "Team"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.organization_name", "HashiCorp"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.phone_number", "+1.4155551234"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.state", "CA"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.zip_code", "94105"), resource.TestCheckResourceAttr(resourceName, "registrant_contact.#", "1"), resource.TestCheckResourceAttr(resourceName, "registrant_contact.0.address_line_1", "101 2nd St #700"), resource.TestCheckResourceAttr(resourceName, "registrant_contact.0.city", "San Francisco"), @@ -192,17 +219,19 @@ func testAccRegisteredDomain_contactPrivacy(t *testing.T) { CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ { - Config: testAccRegisteredDomainConfig_contactPrivacy(domainName, true, true, true), + Config: testAccRegisteredDomainConfig_contactPrivacy(domainName, true, true, true, true), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "admin_privacy", "true"), + resource.TestCheckResourceAttr(resourceName, "billing_privacy", "true"), resource.TestCheckResourceAttr(resourceName, "registrant_privacy", "true"), resource.TestCheckResourceAttr(resourceName, "tech_privacy", "true"), ), }, { - Config: testAccRegisteredDomainConfig_contactPrivacy(domainName, false, false, false), + Config: testAccRegisteredDomainConfig_contactPrivacy(domainName, false, false, false, false), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "admin_privacy", "false"), + resource.TestCheckResourceAttr(resourceName, "billing_privacy", "false"), resource.TestCheckResourceAttr(resourceName, "registrant_privacy", "false"), resource.TestCheckResourceAttr(resourceName, "tech_privacy", "false"), ), @@ -332,6 +361,22 @@ resource "aws_route53domains_registered_domain" "test" { zip_code = "ST1 1AB" } + billing_contact { + address_line_1 = "1 Mawson Street" + address_line_2 = "Unit 2" + city = "Mawson" + contact_type = "PERSON" + country_code = "AU" + email = "terraform-acctest+aws-route53domains-test4@hashicorp.com" + fax = "+61.412345678" + first_name = "John" + last_name = "Cleese" + organization_name = "Monty Python" + phone_number = "+61.412345679" + state = "ACT" + zip_code = "2606" + } + registrant_contact { address_line_1 = "100 Main Street" city = "New York City" @@ -381,6 +426,21 @@ resource "aws_route53domains_registered_domain" "test" { zip_code = "94105" } + billing_contact { + address_line_1 = "101 2nd St #700" + city = "San Francisco" + contact_type = "COMPANY" + country_code = "US" + email = "terraform-acctest+aws@hashicorp.com" + fax = "+1.4155551234" + first_name = "Terraform" + last_name = "Team" + organization_name = "HashiCorp" + phone_number = "+1.4155551234" + state = "CA" + zip_code = "94105" + } + registrant_contact { address_line_1 = "101 2nd St #700" city = "San Francisco" @@ -414,16 +474,17 @@ resource "aws_route53domains_registered_domain" "test" { `, domainName) } -func testAccRegisteredDomainConfig_contactPrivacy(domainName string, adminPrivacy, registrantPrivacy, techPrivacy bool) string { +func testAccRegisteredDomainConfig_contactPrivacy(domainName string, adminPrivacy, billingPrivacy, registrantPrivacy, techPrivacy bool) string { return fmt.Sprintf(` resource "aws_route53domains_registered_domain" "test" { domain_name = %[1]q admin_privacy = %[2]t - registrant_privacy = %[3]t - tech_privacy = %[4]t + billing_privacy = %[3]t + registrant_privacy = %[4]t + tech_privacy = %[5]t } -`, domainName, adminPrivacy, registrantPrivacy, techPrivacy) +`, domainName, adminPrivacy, billingPrivacy, registrantPrivacy, techPrivacy) } func testAccRegisteredDomainConfig_nameservers(domainName string) string { From 91df0fded2e1f6e4b64ce6aed94d17eb9706b154 Mon Sep 17 00:00:00 2001 From: Szasza Palmer Date: Sun, 10 Mar 2024 16:29:22 +1100 Subject: [PATCH 2/8] updating documentation --- website/docs/r/route53domains_registered_domain.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/route53domains_registered_domain.html.markdown b/website/docs/r/route53domains_registered_domain.html.markdown index d44472f9695..f563faf5c95 100644 --- a/website/docs/r/route53domains_registered_domain.html.markdown +++ b/website/docs/r/route53domains_registered_domain.html.markdown @@ -43,6 +43,8 @@ This argument supports the following arguments: * `admin_contact` - (Optional) Details about the domain administrative contact. See [Contact Blocks](#contact-blocks) for more details. * `admin_privacy` - (Optional) Whether domain administrative contact information is concealed from WHOIS queries. Default: `true`. * `auto_renew` - (Optional) Whether the domain registration is set to renew automatically. Default: `true`. +* `billing_contact` - (Optional) Details about the domain billing contact. See [Contact Blocks](#contact-blocks) for more details. +* `billing_privacy` - (Optional) Whether domain billing contact information is concealed from WHOIS queries. Default: `true`. * `domain_name` - (Required) The name of the registered domain. * `name_server` - (Optional) The list of nameservers for the domain. See [`name_server` Blocks](#name_server-blocks) for more details. * `registrant_contact` - (Optional) Details about the domain registrant. See [Contact Blocks](#contact-blocks) for more details. From 152d241eaf07a9d24a912337bf4781d6918422b6 Mon Sep 17 00:00:00 2001 From: Szasza Palmer Date: Sun, 10 Mar 2024 21:13:11 +1100 Subject: [PATCH 3/8] adding changelog --- .changelog/36285.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/36285.txt diff --git a/.changelog/36285.txt b/.changelog/36285.txt new file mode 100644 index 00000000000..c7cc67eef96 --- /dev/null +++ b/.changelog/36285.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_route53domains_registered_domain: Add billing contact and billing privacy support +``` From ddff65f38dfcc8b3de1c3b120bc7488a76d7df58 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 11 Mar 2024 10:30:36 -0400 Subject: [PATCH 4/8] Update 36285.txt --- .changelog/36285.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/36285.txt b/.changelog/36285.txt index c7cc67eef96..17aa663d85b 100644 --- a/.changelog/36285.txt +++ b/.changelog/36285.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_route53domains_registered_domain: Add billing contact and billing privacy support +resource/aws_route53domains_registered_domain: Add `billing_contact` and `billing_privacy` arguments ``` From 2653649a18aee5bcb4722677ec22647752a9dce1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 11 Mar 2024 10:51:02 -0400 Subject: [PATCH 5/8] testAccRegisteredDomain_contacts: Fix 'InvalidInput: Organisation field is not used for PERSON contact type' (#25795). --- internal/service/route53domains/registered_domain_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/service/route53domains/registered_domain_test.go b/internal/service/route53domains/registered_domain_test.go index 1c980717be6..b84250d7c05 100644 --- a/internal/service/route53domains/registered_domain_test.go +++ b/internal/service/route53domains/registered_domain_test.go @@ -118,7 +118,7 @@ func testAccRegisteredDomain_contacts(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "billing_contact.0.fax", "+61.412345678"), resource.TestCheckResourceAttr(resourceName, "billing_contact.0.first_name", "John"), resource.TestCheckResourceAttr(resourceName, "billing_contact.0.last_name", "Cleese"), - resource.TestCheckResourceAttr(resourceName, "billing_contact.0.organization_name", "Monty Python"), + resource.TestCheckResourceAttr(resourceName, "billing_contact.0.organization_name", ""), resource.TestCheckResourceAttr(resourceName, "billing_contact.0.phone_number", "+61.412345679"), resource.TestCheckResourceAttr(resourceName, "billing_contact.0.state", "ACT"), resource.TestCheckResourceAttr(resourceName, "billing_contact.0.zip_code", "2606"), @@ -371,7 +371,6 @@ resource "aws_route53domains_registered_domain" "test" { fax = "+61.412345678" first_name = "John" last_name = "Cleese" - organization_name = "Monty Python" phone_number = "+61.412345679" state = "ACT" zip_code = "2606" From c784aa6939c7470e45bd91fe1fb8a6b90181bb14 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 11 Mar 2024 11:02:04 -0400 Subject: [PATCH 6/8] Fix terrafmt errors. --- .../route53domains/registered_domain_test.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/service/route53domains/registered_domain_test.go b/internal/service/route53domains/registered_domain_test.go index b84250d7c05..620a2380aea 100644 --- a/internal/service/route53domains/registered_domain_test.go +++ b/internal/service/route53domains/registered_domain_test.go @@ -362,18 +362,18 @@ resource "aws_route53domains_registered_domain" "test" { } billing_contact { - address_line_1 = "1 Mawson Street" - address_line_2 = "Unit 2" - city = "Mawson" - contact_type = "PERSON" - country_code = "AU" - email = "terraform-acctest+aws-route53domains-test4@hashicorp.com" - fax = "+61.412345678" - first_name = "John" - last_name = "Cleese" - phone_number = "+61.412345679" - state = "ACT" - zip_code = "2606" + address_line_1 = "1 Mawson Street" + address_line_2 = "Unit 2" + city = "Mawson" + contact_type = "PERSON" + country_code = "AU" + email = "terraform-acctest+aws-route53domains-test4@hashicorp.com" + fax = "+61.412345678" + first_name = "John" + last_name = "Cleese" + phone_number = "+61.412345679" + state = "ACT" + zip_code = "2606" } registrant_contact { From 5709bbddd8bb85e028275912cbe9372470d5c342 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 11 Mar 2024 11:04:45 -0400 Subject: [PATCH 7/8] testAccRegisteredDomain_contacts: Correct contact_type. --- internal/service/route53domains/registered_domain_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/route53domains/registered_domain_test.go b/internal/service/route53domains/registered_domain_test.go index 620a2380aea..dce6d0b9831 100644 --- a/internal/service/route53domains/registered_domain_test.go +++ b/internal/service/route53domains/registered_domain_test.go @@ -99,7 +99,7 @@ func testAccRegisteredDomain_contacts(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "admin_contact.0.address_line_1", "99 High Street"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.address_line_2", "Flat 1a"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.city", "Little Nowhere"), - resource.TestCheckResourceAttr(resourceName, "admin_contact.0.contact_type", "ASSOCIATION"), + resource.TestCheckResourceAttr(resourceName, "admin_contact.0.contact_type", "COMPANY"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.country_code", "GB"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.email", "terraform-acctest+aws-route53domains-test1@hashicorp.com"), resource.TestCheckResourceAttr(resourceName, "admin_contact.0.fax", "+44.123456788"), @@ -350,7 +350,7 @@ resource "aws_route53domains_registered_domain" "test" { address_line_1 = "99 High Street" address_line_2 = "Flat 1a" city = "Little Nowhere" - contact_type = "ASSOCIATION" + contact_type = "COMPANY" country_code = "GB" email = "terraform-acctest+aws-route53domains-test1@hashicorp.com" fax = "+44.123456788" From 3e21001ab42d0383034a6d5773ff6c22fe9aaa80 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 11 Mar 2024 11:21:06 -0400 Subject: [PATCH 8/8] Cosmetics. --- .../service/route53domains/exports_test.go | 1 + .../route53domains/registered_domain.go | 402 +++++++++--------- .../route53domains/service_package_gen.go | 2 +- 3 files changed, 205 insertions(+), 200 deletions(-) diff --git a/internal/service/route53domains/exports_test.go b/internal/service/route53domains/exports_test.go index 8ea09a5720e..b822475abad 100644 --- a/internal/service/route53domains/exports_test.go +++ b/internal/service/route53domains/exports_test.go @@ -6,6 +6,7 @@ package route53domains // Exports for use in tests only. var ( ResourceDelegationSignerRecord = newDelegationSignerRecordResource + ResourceRegisteredDomain = resourceRegisteredDomain FindDNSSECKeyByTwoPartKey = findDNSSECKeyByTwoPartKey ) diff --git a/internal/service/route53domains/registered_domain.go b/internal/service/route53domains/registered_domain.go index 3da20c57724..8c2e4f1da85 100644 --- a/internal/service/route53domains/registered_domain.go +++ b/internal/service/route53domains/registered_domain.go @@ -30,102 +30,7 @@ import ( // @SDKResource("aws_route53domains_registered_domain", name="Registered Domain") // @Tags(identifierAttribute="id") -func ResourceRegisteredDomain() *schema.Resource { - contactSchema := &schema.Schema{ - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "address_line_1": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "address_line_2": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "city": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "contact_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateDiagFunc: enum.Validate[types.ContactType](), - }, - "country_code": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateDiagFunc: enum.Validate[types.CountryCode](), - }, - "email": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 254), - }, - "extra_params": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "fax": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 30), - }, - "first_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "last_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "organization_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "phone_number": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 30), - }, - "state": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - "zip_code": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringLenBetween(0, 255), - }, - }, - }, - } - +func resourceRegisteredDomain() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceRegisteredDomainCreate, ReadWithoutTimeout: resourceRegisteredDomainRead, @@ -141,115 +46,214 @@ func ResourceRegisteredDomain() *schema.Resource { Update: schema.DefaultTimeout(30 * time.Minute), }, - Schema: map[string]*schema.Schema{ - "abuse_contact_email": { - Type: schema.TypeString, - Computed: true, - }, - "abuse_contact_phone": { - Type: schema.TypeString, - Computed: true, - }, - "admin_contact": contactSchema, - "admin_privacy": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "auto_renew": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "billing_contact": contactSchema, - "billing_privacy": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "creation_date": { - Type: schema.TypeString, - Computed: true, - }, - "domain_name": { - Type: schema.TypeString, - Required: true, - }, - "expiration_date": { - Type: schema.TypeString, - Computed: true, - }, - "name_server": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 6, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "glue_ips": { - Type: schema.TypeSet, - Optional: true, - MaxItems: 2, - Elem: &schema.Schema{ + SchemaFunc: func() map[string]*schema.Schema { + contactSchema := func() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "address_line_1": { Type: schema.TypeString, - ValidateFunc: validation.IsIPAddress, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "address_line_2": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "city": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "contact_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[types.ContactType](), + }, + "country_code": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[types.CountryCode](), + }, + "email": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 254), + }, + "extra_params": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "fax": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 30), + }, + "first_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "last_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "organization_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "phone_number": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 30), + }, + "state": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), + }, + "zip_code": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringLenBetween(0, 255), }, }, - "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.All( - validation.StringLenBetween(1, 255), - validation.StringMatch(regexache.MustCompile(`[0-9A-Za-z_.-]*`), "can contain only alphabetical characters (A-Z or a-z), numeric characters (0-9), underscore (_), the minus sign (-), and the period (.)"), - ), + }, + } + } + + return map[string]*schema.Schema{ + "abuse_contact_email": { + Type: schema.TypeString, + Computed: true, + }, + "abuse_contact_phone": { + Type: schema.TypeString, + Computed: true, + }, + "admin_contact": contactSchema(), + "admin_privacy": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "auto_renew": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "billing_contact": contactSchema(), + "billing_privacy": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + "domain_name": { + Type: schema.TypeString, + Required: true, + }, + "expiration_date": { + Type: schema.TypeString, + Computed: true, + }, + "name_server": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 6, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "glue_ips": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 2, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.IsIPAddress, + }, + }, + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.All( + validation.StringLenBetween(1, 255), + validation.StringMatch(regexache.MustCompile(`[0-9A-Za-z_.-]*`), "can contain only alphabetical characters (A-Z or a-z), numeric characters (0-9), underscore (_), the minus sign (-), and the period (.)"), + ), + }, }, }, }, - }, - "registrant_contact": contactSchema, - "registrant_privacy": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "registrar_name": { - Type: schema.TypeString, - Computed: true, - }, - "registrar_url": { - Type: schema.TypeString, - Computed: true, - }, - "reseller": { - Type: schema.TypeString, - Computed: true, - }, - "status_list": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - names.AttrTags: tftags.TagsSchema(), - names.AttrTagsAll: tftags.TagsSchemaComputed(), - "tech_contact": contactSchema, - "tech_privacy": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "transfer_lock": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "updated_date": { - Type: schema.TypeString, - Computed: true, - }, - "whois_server": { - Type: schema.TypeString, - Computed: true, - }, + "registrant_contact": contactSchema(), + "registrant_privacy": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "registrar_name": { + Type: schema.TypeString, + Computed: true, + }, + "registrar_url": { + Type: schema.TypeString, + Computed: true, + }, + "reseller": { + Type: schema.TypeString, + Computed: true, + }, + "status_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), + "tech_contact": contactSchema(), + "tech_privacy": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "transfer_lock": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "updated_date": { + Type: schema.TypeString, + Computed: true, + }, + "whois_server": { + Type: schema.TypeString, + Computed: true, + }, + } }, CustomizeDiff: verify.SetTagsDiff, diff --git a/internal/service/route53domains/service_package_gen.go b/internal/service/route53domains/service_package_gen.go index 334b9f90f04..6f4aa87b194 100644 --- a/internal/service/route53domains/service_package_gen.go +++ b/internal/service/route53domains/service_package_gen.go @@ -32,7 +32,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceRegisteredDomain, + Factory: resourceRegisteredDomain, TypeName: "aws_route53domains_registered_domain", Name: "Registered Domain", Tags: &types.ServicePackageResourceTags{