Skip to content

Commit

Permalink
fix managed.dnsAuthorizations: (#7445) (#5325)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Mar 14, 2023
1 parent 69caf3f commit 371c678
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/7445.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
certificatemanager: fixed `managed.dnsAuthorizations` is missing in import from `google_certificate_manager_certificate`
```
11 changes: 6 additions & 5 deletions google-beta/resource_certificate_manager_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ automatically, for as long as it's authorized to do so.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_authorizations": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Authorizations that will be used for performing domain authorization`,
Type: schema.TypeList,
Optional: true,
ForceNew: true,
DiffSuppressFunc: projectNumberDiffSuppress,
Description: `Authorizations that will be used for performing domain authorization`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down Expand Up @@ -545,7 +546,7 @@ func flattenCertificateManagerCertificateManagedDomains(v interface{}, d *schema
}

func flattenCertificateManagerCertificateManagedDnsAuthorizations(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return d.Get("managed.0.dns_authorizations")
return v
}

func flattenCertificateManagerCertificateManagedState(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,64 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

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

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

VcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: TestAccProviders,
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateExample(context),
},
{
ResourceName: "google_certificate_manager_certificate.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"self_managed", "name"},
},
},
})
}

func testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_certificate_manager_certificate" "default" {
name = "tf-test-dns-cert%{random_suffix}"
description = "The default cert"
scope = "EDGE_CACHE"
managed {
domains = [
google_certificate_manager_dns_authorization.instance.domain,
google_certificate_manager_dns_authorization.instance2.domain,
]
dns_authorizations = [
google_certificate_manager_dns_authorization.instance.id,
google_certificate_manager_dns_authorization.instance2.id,
]
}
}
resource "google_certificate_manager_dns_authorization" "instance" {
name = "tf-test-dns-auth%{random_suffix}"
description = "The default dnss"
domain = "subdomain%{random_suffix}.hashicorptest.com"
}
resource "google_certificate_manager_dns_authorization" "instance2" {
name = "tf-test-dns-auth2%{random_suffix}"
description = "The default dnss"
domain = "subdomain2%{random_suffix}.hashicorptest.com"
}
`, context)
}

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

Expand Down
38 changes: 38 additions & 0 deletions website/docs/r/certificate_manager_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ Certificate represents a HTTP-reachable backend for a Certificate.
~> **Warning:** All arguments including `self_managed.certificate_pem`, `self_managed.private_key_pem`, and `self_managed.pem_private_key` will be stored in the raw
state as plain-text. [Read more about sensitive data in state](https://www.terraform.io/language/state/sensitive-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_google_managed_certificate&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%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 Certificate


```hcl
resource "google_certificate_manager_certificate" "default" {
name = "dns-cert"
description = "The default cert"
scope = "EDGE_CACHE"
managed {
domains = [
google_certificate_manager_dns_authorization.instance.domain,
google_certificate_manager_dns_authorization.instance2.domain,
]
dns_authorizations = [
google_certificate_manager_dns_authorization.instance.id,
google_certificate_manager_dns_authorization.instance2.id,
]
}
}
resource "google_certificate_manager_dns_authorization" "instance" {
name = "dns-auth"
description = "The default dnss"
domain = "subdomain.hashicorptest.com"
}
resource "google_certificate_manager_dns_authorization" "instance2" {
name = "dns-auth2"
description = "The default dnss"
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_self_managed_certificate&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%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%;">
Expand Down

0 comments on commit 371c678

Please sign in to comment.