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

Add type field to DNS authorization reosurce #7036

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/10030.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
certificatemanager: added `type` field to `google_certificate_manager_dns_authorization` resource

```
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,55 @@ resource "google_certificate_manager_dns_authorization" "instance2" {
`, context)
}

func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedRegionalCertificateDnsAuthExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCertificateManagerCertificate_certificateManagerGoogleManagedRegionalCertificateDnsAuthExample(context),
},
{
ResourceName: "google_certificate_manager_certificate.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"self_managed", "name", "location", "labels", "terraform_labels"},
},
},
})
}

func testAccCertificateManagerCertificate_certificateManagerGoogleManagedRegionalCertificateDnsAuthExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_certificate_manager_certificate" "default" {
name = "tf-test-dns-cert%{random_suffix}"
description = "regional managed certs"
location = "us-central1"
managed {
domains = [
google_certificate_manager_dns_authorization.instance.domain,
]
dns_authorizations = [
google_certificate_manager_dns_authorization.instance.id,
]
}
}
resource "google_certificate_manager_dns_authorization" "instance" {
name = "tf-test-dns-auth%{random_suffix}"
location = "us-central1"
description = "The default dnss"
domain = "subdomain%{random_suffix}.hashicorptest.com"
}
`, context)
}

func testAccCheckCertificateManagerCertificateDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
)

func ResourceCertificateManagerDnsAuthorization() *schema.Resource {
Expand Down Expand Up @@ -101,6 +102,21 @@ Please refer to the field 'effective_labels' for all of the labels present on th
Description: `The Certificate Manager location. If not specified, "global" is used.`,
Default: "global",
},
"type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"FIXED_RECORD", "PER_PROJECT_RECORD", ""}),
Description: `type of DNS authorization. If unset during the resource creation, FIXED_RECORD will
be used for global resources, and PER_PROJECT_RECORD will be used for other locations.

FIXED_RECORD DNS authorization uses DNS-01 validation method

PER_PROJECT_RECORD DNS authorization allows for independent management
of Google-managed certificates with DNS authorization across multiple
projects. Possible values: ["FIXED_RECORD", "PER_PROJECT_RECORD"]`,
},
"dns_resource_record": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -172,6 +188,12 @@ func resourceCertificateManagerDnsAuthorizationCreate(d *schema.ResourceData, me
} else if v, ok := d.GetOkExists("domain"); !tpgresource.IsEmptyValue(reflect.ValueOf(domainProp)) && (ok || !reflect.DeepEqual(v, domainProp)) {
obj["domain"] = domainProp
}
typeProp, err := expandCertificateManagerDnsAuthorizationType(d.Get("type"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
labelsProp, err := expandCertificateManagerDnsAuthorizationEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -282,6 +304,9 @@ func resourceCertificateManagerDnsAuthorizationRead(d *schema.ResourceData, meta
if err := d.Set("domain", flattenCertificateManagerDnsAuthorizationDomain(res["domain"], d, config)); err != nil {
return fmt.Errorf("Error reading DnsAuthorization: %s", err)
}
if err := d.Set("type", flattenCertificateManagerDnsAuthorizationType(res["type"], d, config)); err != nil {
return fmt.Errorf("Error reading DnsAuthorization: %s", err)
}
if err := d.Set("dns_resource_record", flattenCertificateManagerDnsAuthorizationDnsResourceRecord(res["dnsResourceRecord"], d, config)); err != nil {
return fmt.Errorf("Error reading DnsAuthorization: %s", err)
}
Expand Down Expand Up @@ -477,6 +502,10 @@ func flattenCertificateManagerDnsAuthorizationDomain(v interface{}, d *schema.Re
return v
}

func flattenCertificateManagerDnsAuthorizationType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenCertificateManagerDnsAuthorizationDnsResourceRecord(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -533,6 +562,10 @@ func expandCertificateManagerDnsAuthorizationDomain(v interface{}, d tpgresource
return v, nil
}

func expandCertificateManagerDnsAuthorizationType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCertificateManagerDnsAuthorizationEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ output "record_data_to_insert" {
`, context)
}

func TestAccCertificateManagerDnsAuthorization_certificateManagerDnsAuthorizationRegionalExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckCertificateManagerDnsAuthorizationDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCertificateManagerDnsAuthorization_certificateManagerDnsAuthorizationRegionalExample(context),
},
{
ResourceName: "google_certificate_manager_dns_authorization.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location", "labels", "terraform_labels"},
},
},
})
}

func testAccCertificateManagerDnsAuthorization_certificateManagerDnsAuthorizationRegionalExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_certificate_manager_dns_authorization" "default" {
name = "tf-test-dns-auth%{random_suffix}"
location = "us-central1"
description = "reginal dns"
type = "PER_PROJECT_RECORD"
domain = "subdomain%{random_suffix}.hashicorptest.com"
}
`, context)
}

func testAccCheckCertificateManagerDnsAuthorizationDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
29 changes: 29 additions & 0 deletions website/docs/r/certificate_manager_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,35 @@ resource "google_certificate_manager_dns_authorization" "instance2" {
domain = "subdomain2.hashicorptest.com"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Certificate Manager Google Managed Regional Certificate Dns Auth


```hcl
resource "google_certificate_manager_certificate" "default" {
name = "dns-cert"
description = "regional managed certs"
location = "us-central1"
managed {
domains = [
google_certificate_manager_dns_authorization.instance.domain,
]
dns_authorizations = [
google_certificate_manager_dns_authorization.instance.id,
]
}
}
resource "google_certificate_manager_dns_authorization" "instance" {
name = "dns-auth"
location = "us-central1"
description = "The default dnss"
domain = "subdomain.hashicorptest.com"
}
```

## Argument Reference

Expand Down
27 changes: 27 additions & 0 deletions website/docs/r/certificate_manager_dns_authorization.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ output "record_data_to_insert" {
value = google_certificate_manager_dns_authorization.default.dns_resource_record.0.data
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Certificate Manager Dns Authorization Regional


```hcl
resource "google_certificate_manager_dns_authorization" "default" {
name = "dns-auth"
location = "us-central1"
description = "reginal dns"
type = "PER_PROJECT_RECORD"
domain = "subdomain.hashicorptest.com"
}
```

## Argument Reference

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

* `type` -
(Optional)
type of DNS authorization. If unset during the resource creation, FIXED_RECORD will
be used for global resources, and PER_PROJECT_RECORD will be used for other locations.
FIXED_RECORD DNS authorization uses DNS-01 validation method
PER_PROJECT_RECORD DNS authorization allows for independent management
of Google-managed certificates with DNS authorization across multiple
projects.
Possible values are: `FIXED_RECORD`, `PER_PROJECT_RECORD`.

* `location` -
(Optional)
The Certificate Manager location. If not specified, "global" is used.
Expand Down