Skip to content

Commit d0bba35

Browse files
Add type field to DNS authorization reosurce (#10030) (#17459)
* Add type field to DNS authorization reosurce * Add an example for regional DNS authorization * Add an example for regional certs using regional DNS auth * Fix lint errors * Fix typo in the enum values * Add type field in regional dns auth example --------- [upstream:0ac8f5283f99aca69ac1821ecbc67200d45b0390] Signed-off-by: Modular Magician <[email protected]>
1 parent ef4977a commit d0bba35

6 files changed

+179
-0
lines changed

.changelog/10030.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
certificatemanager: added `type` field to `google_certificate_manager_dns_authorization` resource
3+
4+
```

google/services/certificatemanager/resource_certificate_manager_certificate_generated_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,55 @@ resource "google_certificate_manager_dns_authorization" "instance2" {
433433
`, context)
434434
}
435435

436+
func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedRegionalCertificateDnsAuthExample(t *testing.T) {
437+
t.Parallel()
438+
439+
context := map[string]interface{}{
440+
"random_suffix": acctest.RandString(t, 10),
441+
}
442+
443+
acctest.VcrTest(t, resource.TestCase{
444+
PreCheck: func() { acctest.AccTestPreCheck(t) },
445+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
446+
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
447+
Steps: []resource.TestStep{
448+
{
449+
Config: testAccCertificateManagerCertificate_certificateManagerGoogleManagedRegionalCertificateDnsAuthExample(context),
450+
},
451+
{
452+
ResourceName: "google_certificate_manager_certificate.default",
453+
ImportState: true,
454+
ImportStateVerify: true,
455+
ImportStateVerifyIgnore: []string{"self_managed", "name", "location", "labels", "terraform_labels"},
456+
},
457+
},
458+
})
459+
}
460+
461+
func testAccCertificateManagerCertificate_certificateManagerGoogleManagedRegionalCertificateDnsAuthExample(context map[string]interface{}) string {
462+
return acctest.Nprintf(`
463+
resource "google_certificate_manager_certificate" "default" {
464+
name = "tf-test-dns-cert%{random_suffix}"
465+
description = "regional managed certs"
466+
location = "us-central1"
467+
managed {
468+
domains = [
469+
google_certificate_manager_dns_authorization.instance.domain,
470+
]
471+
dns_authorizations = [
472+
google_certificate_manager_dns_authorization.instance.id,
473+
]
474+
}
475+
}
476+
resource "google_certificate_manager_dns_authorization" "instance" {
477+
name = "tf-test-dns-auth%{random_suffix}"
478+
location = "us-central1"
479+
description = "The default dnss"
480+
domain = "subdomain%{random_suffix}.hashicorptest.com"
481+
}
482+
`, context)
483+
}
484+
436485
func testAccCheckCertificateManagerCertificateDestroyProducer(t *testing.T) func(s *terraform.State) error {
437486
return func(s *terraform.State) error {
438487
for name, rs := range s.RootModule().Resources {

google/services/certificatemanager/resource_certificate_manager_dns_authorization.go

+33
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
3232
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
33+
"github.com/hashicorp/terraform-provider-google/google/verify"
3334
)
3435

3536
func ResourceCertificateManagerDnsAuthorization() *schema.Resource {
@@ -101,6 +102,21 @@ Please refer to the field 'effective_labels' for all of the labels present on th
101102
Description: `The Certificate Manager location. If not specified, "global" is used.`,
102103
Default: "global",
103104
},
105+
"type": {
106+
Type: schema.TypeString,
107+
Computed: true,
108+
Optional: true,
109+
ForceNew: true,
110+
ValidateFunc: verify.ValidateEnum([]string{"FIXED_RECORD", "PER_PROJECT_RECORD", ""}),
111+
Description: `type of DNS authorization. If unset during the resource creation, FIXED_RECORD will
112+
be used for global resources, and PER_PROJECT_RECORD will be used for other locations.
113+
114+
FIXED_RECORD DNS authorization uses DNS-01 validation method
115+
116+
PER_PROJECT_RECORD DNS authorization allows for independent management
117+
of Google-managed certificates with DNS authorization across multiple
118+
projects. Possible values: ["FIXED_RECORD", "PER_PROJECT_RECORD"]`,
119+
},
104120
"dns_resource_record": {
105121
Type: schema.TypeList,
106122
Computed: true,
@@ -172,6 +188,12 @@ func resourceCertificateManagerDnsAuthorizationCreate(d *schema.ResourceData, me
172188
} else if v, ok := d.GetOkExists("domain"); !tpgresource.IsEmptyValue(reflect.ValueOf(domainProp)) && (ok || !reflect.DeepEqual(v, domainProp)) {
173189
obj["domain"] = domainProp
174190
}
191+
typeProp, err := expandCertificateManagerDnsAuthorizationType(d.Get("type"), d, config)
192+
if err != nil {
193+
return err
194+
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
195+
obj["type"] = typeProp
196+
}
175197
labelsProp, err := expandCertificateManagerDnsAuthorizationEffectiveLabels(d.Get("effective_labels"), d, config)
176198
if err != nil {
177199
return err
@@ -282,6 +304,9 @@ func resourceCertificateManagerDnsAuthorizationRead(d *schema.ResourceData, meta
282304
if err := d.Set("domain", flattenCertificateManagerDnsAuthorizationDomain(res["domain"], d, config)); err != nil {
283305
return fmt.Errorf("Error reading DnsAuthorization: %s", err)
284306
}
307+
if err := d.Set("type", flattenCertificateManagerDnsAuthorizationType(res["type"], d, config)); err != nil {
308+
return fmt.Errorf("Error reading DnsAuthorization: %s", err)
309+
}
285310
if err := d.Set("dns_resource_record", flattenCertificateManagerDnsAuthorizationDnsResourceRecord(res["dnsResourceRecord"], d, config)); err != nil {
286311
return fmt.Errorf("Error reading DnsAuthorization: %s", err)
287312
}
@@ -477,6 +502,10 @@ func flattenCertificateManagerDnsAuthorizationDomain(v interface{}, d *schema.Re
477502
return v
478503
}
479504

505+
func flattenCertificateManagerDnsAuthorizationType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
506+
return v
507+
}
508+
480509
func flattenCertificateManagerDnsAuthorizationDnsResourceRecord(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
481510
if v == nil {
482511
return nil
@@ -533,6 +562,10 @@ func expandCertificateManagerDnsAuthorizationDomain(v interface{}, d tpgresource
533562
return v, nil
534563
}
535564

565+
func expandCertificateManagerDnsAuthorizationType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
566+
return v, nil
567+
}
568+
536569
func expandCertificateManagerDnsAuthorizationEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
537570
if v == nil {
538571
return map[string]string{}, nil

google/services/certificatemanager/resource_certificate_manager_dns_authorization_generated_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,43 @@ output "record_data_to_insert" {
7878
`, context)
7979
}
8080

81+
func TestAccCertificateManagerDnsAuthorization_certificateManagerDnsAuthorizationRegionalExample(t *testing.T) {
82+
t.Parallel()
83+
84+
context := map[string]interface{}{
85+
"random_suffix": acctest.RandString(t, 10),
86+
}
87+
88+
acctest.VcrTest(t, resource.TestCase{
89+
PreCheck: func() { acctest.AccTestPreCheck(t) },
90+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
91+
CheckDestroy: testAccCheckCertificateManagerDnsAuthorizationDestroyProducer(t),
92+
Steps: []resource.TestStep{
93+
{
94+
Config: testAccCertificateManagerDnsAuthorization_certificateManagerDnsAuthorizationRegionalExample(context),
95+
},
96+
{
97+
ResourceName: "google_certificate_manager_dns_authorization.default",
98+
ImportState: true,
99+
ImportStateVerify: true,
100+
ImportStateVerifyIgnore: []string{"name", "location", "labels", "terraform_labels"},
101+
},
102+
},
103+
})
104+
}
105+
106+
func testAccCertificateManagerDnsAuthorization_certificateManagerDnsAuthorizationRegionalExample(context map[string]interface{}) string {
107+
return acctest.Nprintf(`
108+
resource "google_certificate_manager_dns_authorization" "default" {
109+
name = "tf-test-dns-auth%{random_suffix}"
110+
location = "us-central1"
111+
description = "reginal dns"
112+
type = "PER_PROJECT_RECORD"
113+
domain = "subdomain%{random_suffix}.hashicorptest.com"
114+
}
115+
`, context)
116+
}
117+
81118
func testAccCheckCertificateManagerDnsAuthorizationDestroyProducer(t *testing.T) func(s *terraform.State) error {
82119
return func(s *terraform.State) error {
83120
for name, rs := range s.RootModule().Resources {

website/docs/r/certificate_manager_certificate.html.markdown

+29
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,35 @@ resource "google_certificate_manager_dns_authorization" "instance2" {
310310
domain = "subdomain2.hashicorptest.com"
311311
}
312312
```
313+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
314+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=certificate_manager_google_managed_regional_certificate_dns_auth&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
315+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
316+
</a>
317+
</div>
318+
## Example Usage - Certificate Manager Google Managed Regional Certificate Dns Auth
319+
320+
321+
```hcl
322+
resource "google_certificate_manager_certificate" "default" {
323+
name = "dns-cert"
324+
description = "regional managed certs"
325+
location = "us-central1"
326+
managed {
327+
domains = [
328+
google_certificate_manager_dns_authorization.instance.domain,
329+
]
330+
dns_authorizations = [
331+
google_certificate_manager_dns_authorization.instance.id,
332+
]
333+
}
334+
}
335+
resource "google_certificate_manager_dns_authorization" "instance" {
336+
name = "dns-auth"
337+
location = "us-central1"
338+
description = "The default dnss"
339+
domain = "subdomain.hashicorptest.com"
340+
}
341+
```
313342

314343
## Argument Reference
315344

website/docs/r/certificate_manager_dns_authorization.html.markdown

+27
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ output "record_data_to_insert" {
5151
value = google_certificate_manager_dns_authorization.default.dns_resource_record.0.data
5252
}
5353
```
54+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
55+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=certificate_manager_dns_authorization_regional&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
56+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
57+
</a>
58+
</div>
59+
## Example Usage - Certificate Manager Dns Authorization Regional
60+
61+
62+
```hcl
63+
resource "google_certificate_manager_dns_authorization" "default" {
64+
name = "dns-auth"
65+
location = "us-central1"
66+
description = "reginal dns"
67+
type = "PER_PROJECT_RECORD"
68+
domain = "subdomain.hashicorptest.com"
69+
}
70+
```
5471

5572
## Argument Reference
5673

@@ -83,6 +100,16 @@ The following arguments are supported:
83100
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
84101
Please refer to the field `effective_labels` for all of the labels present on the resource.
85102

103+
* `type` -
104+
(Optional)
105+
type of DNS authorization. If unset during the resource creation, FIXED_RECORD will
106+
be used for global resources, and PER_PROJECT_RECORD will be used for other locations.
107+
FIXED_RECORD DNS authorization uses DNS-01 validation method
108+
PER_PROJECT_RECORD DNS authorization allows for independent management
109+
of Google-managed certificates with DNS authorization across multiple
110+
projects.
111+
Possible values are: `FIXED_RECORD`, `PER_PROJECT_RECORD`.
112+
86113
* `location` -
87114
(Optional)
88115
The Certificate Manager location. If not specified, "global" is used.

0 commit comments

Comments
 (0)