Skip to content

Commit

Permalink
add old attribute names back in to prevent breaking change (#6607) (#…
Browse files Browse the repository at this point in the history
…4728)

Co-authored-by: megan07 <[email protected]>
Co-authored-by: Pawel Krawczyk <[email protected]>
Co-authored-by: pawel-grz-krawczyk <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: megan07 <[email protected]>
Co-authored-by: Pawel Krawczyk <[email protected]>
Co-authored-by: pawel-grz-krawczyk <[email protected]>
  • Loading branch information
4 people authored Sep 27, 2022
1 parent 37b98fb commit f2ff8f7
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .changelog/6607.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
certificatemanager: added public/private PEM fields `pem_certificate` / `pem_private_key` and deprecated `certificate_pem` / `private_key_pem`
```
79 changes: 47 additions & 32 deletions google-beta/resource_certificate_manager_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,40 @@ certificates before they expire remains the user's responsibility.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"certificate_pem": {
Type: schema.TypeString,
Optional: true,
Deprecated: "Deprecated in favor of `pem_certificate`",
Description: `**Deprecated** The certificate chain in PEM-encoded form.
Leaf certificate comes first, followed by intermediate ones if any.`,
Sensitive: true,
ExactlyOneOf: []string{"self_managed.0.certificate_pem", "self_managed.0.pem_certificate"},
},
"pem_certificate": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: `The certificate chain in PEM-encoded form.
Leaf certificate comes first, followed by intermediate ones if any.`,
Sensitive: true,
ExactlyOneOf: []string{"self_managed.0.certificate_pem", "self_managed.0.pem_certificate"},
},
"pem_private_key": {
Type: schema.TypeString,
Optional: true,
Description: `The private key of the leaf certificate in PEM-encoded form.`,
ExactlyOneOf: []string{"self_managed.0.private_key_pem", "self_managed.0.pem_private_key"},
},
"private_key_pem": {
Type: schema.TypeString,
Required: true,
Description: `The private key of the leaf certificate in PEM-encoded form.`,
Sensitive: true,
Type: schema.TypeString,
Optional: true,
Deprecated: "Deprecated in favor of `pem_private_key`",
Description: `**Deprecated** The private key of the leaf certificate in PEM-encoded form.`,
Sensitive: true,
ExactlyOneOf: []string{"self_managed.0.private_key_pem", "self_managed.0.pem_private_key"},
},
},
},
Sensitive: true,
ExactlyOneOf: []string{"self_managed", "managed"},
},
"project": {
Expand Down Expand Up @@ -341,9 +360,6 @@ func resourceCertificateManagerCertificateRead(d *schema.ResourceData, meta inte
if err := d.Set("scope", flattenCertificateManagerCertificateScope(res["scope"], d, config)); err != nil {
return fmt.Errorf("Error reading Certificate: %s", err)
}
if err := d.Set("self_managed", flattenCertificateManagerCertificateSelfManaged(res["selfManaged"], d, config)); err != nil {
return fmt.Errorf("Error reading Certificate: %s", err)
}
if err := d.Set("managed", flattenCertificateManagerCertificateManaged(res["managed"], d, config)); err != nil {
return fmt.Errorf("Error reading Certificate: %s", err)
}
Expand Down Expand Up @@ -503,29 +519,6 @@ func flattenCertificateManagerCertificateScope(v interface{}, d *schema.Resource
return v
}

func flattenCertificateManagerCertificateSelfManaged(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["certificate_pem"] =
flattenCertificateManagerCertificateSelfManagedCertificatePem(original["certificatePem"], d, config)
transformed["private_key_pem"] =
flattenCertificateManagerCertificateSelfManagedPrivateKeyPem(original["privateKeyPem"], d, config)
return []interface{}{transformed}
}
func flattenCertificateManagerCertificateSelfManagedCertificatePem(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

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

func flattenCertificateManagerCertificateManaged(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -661,6 +654,20 @@ func expandCertificateManagerCertificateSelfManaged(v interface{}, d TerraformRe
transformed["privateKeyPem"] = transformedPrivateKeyPem
}

transformedPemCertificate, err := expandCertificateManagerCertificateSelfManagedPemCertificate(original["pem_certificate"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPemCertificate); val.IsValid() && !isEmptyValue(val) {
transformed["pemCertificate"] = transformedPemCertificate
}

transformedPemPrivateKey, err := expandCertificateManagerCertificateSelfManagedPemPrivateKey(original["pem_private_key"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPemPrivateKey); val.IsValid() && !isEmptyValue(val) {
transformed["pemPrivateKey"] = transformedPemPrivateKey
}

return transformed, nil
}

Expand All @@ -672,6 +679,14 @@ func expandCertificateManagerCertificateSelfManagedPrivateKeyPem(v interface{},
return v, nil
}

func expandCertificateManagerCertificateSelfManagedPemCertificate(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCertificateManagerCertificateSelfManagedPemPrivateKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCertificateManagerCertificateManaged(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

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

context := map[string]interface{}{
Expand All @@ -36,48 +36,29 @@ func TestAccCertificateManagerCertificate_certificateManagerCertificateBasicExam
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccCertificateManagerCertificate_certificateManagerCertificateBasicExample(context),
Config: testAccCertificateManagerCertificate_certificateManagerSelfManagedCertificateExample(context),
},
{
ResourceName: "google_certificate_manager_certificate.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "managed.0.dns_authorizations"},
ImportStateVerifyIgnore: []string{"self_managed", "name"},
},
},
})
}

func testAccCertificateManagerCertificate_certificateManagerCertificateBasicExample(context map[string]interface{}) string {
func testAccCertificateManagerCertificate_certificateManagerSelfManagedCertificateExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_certificate_manager_certificate" "default" {
name = "tf-test-dns-cert%{random_suffix}"
name = "tf-test-self-managed-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,
]
self_managed {
pem_certificate = file("test-fixtures/certificatemanager/cert.pem")
pem_private_key = file("test-fixtures/certificatemanager/private-key.pem")
}
}
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)
}

Expand Down
19 changes: 19 additions & 0 deletions google-beta/test-fixtures/certificatemanager/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDDzCCAfegAwIBAgIUDOiCLH9QNMMYnjPZVf4VwO9blsEwDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wIBcNMjIwODI0MDg0MDUxWhgPMzAy
MTEyMjUwODQwNTFaMBYxFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvOT925GG4lKV9HvAHsbecMhGPAqjhVRC26iZ
UJC8oSWOu95lWJSX5ZhbiF6Nz192wDGV/VAh3Lxj8RYtcn75eDxQKTcKouDld+To
CGIStPFWbR6rbysLuZqFVEXVOTvp2QIegInfrvnGC4j7Qpic7zrFB9HzJx+0HpeE
yO4gkdzJfEK/gMmolUgJrKX59o+0+Rj+Jq3EtcQxL1fVBVJSx0NvpoR1eYpnHMr/
rJKZkUUZ2xE86hrtpiP6OEYQTi00rmf4GnZF5QfGGD0xuoQXtR7Tu+XhKibXIhxc
D4RzPLX1QS040PXvmMPLDb4YlUQ6V3Rs42JDvkkDwIMXZvn8awIDAQABo1MwUTAd
BgNVHQ4EFgQURuo1CCZZAUv7xi02f2nC5tRbf18wHwYDVR0jBBgwFoAURuo1CCZZ
AUv7xi02f2nC5tRbf18wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC
AQEAqx3tDxurnYr9EUPhF5/LlDPYM+VI7EgrKdRnuIqUlZI0tm3vOGME0te6dBTC
YLNaHLW3m/4Tm4M2eg0Kpz6CxJfn3109G31dCi0xwzSDHf5TPUWvqIVhq5WRgMIf
n8KYBlQSmqdJBRztUIQH/UPFnSbxymlS4s5qwDgTH5ag9EEBcnWsQ2LZjKi0eqve
MaqAvvB+j8RGZzYY4re94bSJI42zIZ6nMWPtXwRuDc30xl/u+E0jWIgWbPwSd6Km
3wnJnGiU2ezPGq3zEU+Rc39VVIFKQpciNeYuF3neHPJvYOf58qW2Z8s0VH0MR1x3
3DoO/e30FIr9j+PRD+s5BPKF2A==
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions google-beta/test-fixtures/certificatemanager/private-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC85P3bkYbiUpX0
e8Aext5wyEY8CqOFVELbqJlQkLyhJY673mVYlJflmFuIXo3PX3bAMZX9UCHcvGPx
Fi1yfvl4PFApNwqi4OV35OgIYhK08VZtHqtvKwu5moV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J5RUZ6hwCjvHedX3/RQfjnEdhHNOl6/31Zj5mfkVU0zdqeRAoGAcvIh
erXMfPr7K6y16+xOCMmKHqhc0F/OZXMmSdxNzEPcqe8GzU3MZLxcJIg4oH7FqdtI
Tm/86w4Spd9owHFMZlNcXYTu+LNZcsw2u0gRayxcZXuO3OyHySxZEuIAHSTBCZ7l
3EoY0zfJ6zk249MEl6n+GouoFmbGpBI6z3zbR3kCgYEAlCNZVH4uJrP5beTOZTTR
VJRk7BXvEC6HsM140YtIN7NHy2GtzrgmmY/ZAFB/hX8Ft4ex2MxbIp3hvxroTqGn
bfu7uv97NoPQqbjtc3Mz8h2IaXTVDUnWYY5gDu6rM2w+Z75/sWIGiTWrsdYX4ohb
ujngzJ7Ew7GgKSboj6mtlVM=
-----END PRIVATE KEY-----
51 changes: 21 additions & 30 deletions website/docs/r/certificate_manager_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,27 @@ Certificate represents a HTTP-reachable backend for a Certificate.



~> **Warning:** All arguments including `self_managed.certificate_pem` and `self_managed.private_key_pem` will be stored in the raw
~> **Warning:** All arguments including `self_managed`, `self_managed.certificate_pem`, and `self_managed.private_key_pem` 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_certificate_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<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%;">
</a>
</div>
## Example Usage - Certificate Manager Certificate Basic
## Example Usage - Certificate Manager Self Managed Certificate


```hcl
resource "google_certificate_manager_certificate" "default" {
name = "dns-cert"
name = "self-managed-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,
]
self_managed {
pem_certificate = file("test-fixtures/certificatemanager/cert.pem")
pem_private_key = file("test-fixtures/certificatemanager/private-key.pem")
}
}
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"
}
```

## Argument Reference
Expand Down Expand Up @@ -103,6 +84,7 @@ The following arguments are supported:
Certificate data for a SelfManaged Certificate.
SelfManaged Certificates are uploaded by the user. Updating such
certificates before they expire remains the user's responsibility.
**Note**: This property is sensitive and will not be displayed in the plan.
Structure is [documented below](#nested_self_managed).

* `managed` -
Expand All @@ -119,16 +101,25 @@ The following arguments are supported:
<a name="nested_self_managed"></a>The `self_managed` block supports:

* `certificate_pem` -
(Required)
The certificate chain in PEM-encoded form.
(Optional, Deprecated)
**Deprecated** The certificate chain in PEM-encoded form.
Leaf certificate comes first, followed by intermediate ones if any.
**Note**: This property is sensitive and will not be displayed in the plan.

* `private_key_pem` -
(Required)
The private key of the leaf certificate in PEM-encoded form.
(Optional, Deprecated)
**Deprecated** The private key of the leaf certificate in PEM-encoded form.
**Note**: This property is sensitive and will not be displayed in the plan.

* `pem_certificate` -
(Optional)
The certificate chain in PEM-encoded form.
Leaf certificate comes first, followed by intermediate ones if any.

* `pem_private_key` -
(Optional)
The private key of the leaf certificate in PEM-encoded form.

<a name="nested_managed"></a>The `managed` block supports:

* `domains` -
Expand Down

0 comments on commit f2ff8f7

Please sign in to comment.