Skip to content

Commit f2ff8f7

Browse files
modular-magicianmegan07pkk33
authored
add old attribute names back in to prevent breaking change (#6607) (#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]>
1 parent 37b98fb commit f2ff8f7

File tree

6 files changed

+126
-89
lines changed

6 files changed

+126
-89
lines changed

.changelog/6607.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
certificatemanager: added public/private PEM fields `pem_certificate` / `pem_private_key` and deprecated `certificate_pem` / `private_key_pem`
3+
```

google-beta/resource_certificate_manager_certificate.go

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,40 @@ certificates before they expire remains the user's responsibility.`,
185185
Elem: &schema.Resource{
186186
Schema: map[string]*schema.Schema{
187187
"certificate_pem": {
188+
Type: schema.TypeString,
189+
Optional: true,
190+
Deprecated: "Deprecated in favor of `pem_certificate`",
191+
Description: `**Deprecated** The certificate chain in PEM-encoded form.
192+
193+
Leaf certificate comes first, followed by intermediate ones if any.`,
194+
Sensitive: true,
195+
ExactlyOneOf: []string{"self_managed.0.certificate_pem", "self_managed.0.pem_certificate"},
196+
},
197+
"pem_certificate": {
188198
Type: schema.TypeString,
189-
Required: true,
199+
Optional: true,
190200
Description: `The certificate chain in PEM-encoded form.
191201
192202
Leaf certificate comes first, followed by intermediate ones if any.`,
193-
Sensitive: true,
203+
ExactlyOneOf: []string{"self_managed.0.certificate_pem", "self_managed.0.pem_certificate"},
204+
},
205+
"pem_private_key": {
206+
Type: schema.TypeString,
207+
Optional: true,
208+
Description: `The private key of the leaf certificate in PEM-encoded form.`,
209+
ExactlyOneOf: []string{"self_managed.0.private_key_pem", "self_managed.0.pem_private_key"},
194210
},
195211
"private_key_pem": {
196-
Type: schema.TypeString,
197-
Required: true,
198-
Description: `The private key of the leaf certificate in PEM-encoded form.`,
199-
Sensitive: true,
212+
Type: schema.TypeString,
213+
Optional: true,
214+
Deprecated: "Deprecated in favor of `pem_private_key`",
215+
Description: `**Deprecated** The private key of the leaf certificate in PEM-encoded form.`,
216+
Sensitive: true,
217+
ExactlyOneOf: []string{"self_managed.0.private_key_pem", "self_managed.0.pem_private_key"},
200218
},
201219
},
202220
},
221+
Sensitive: true,
203222
ExactlyOneOf: []string{"self_managed", "managed"},
204223
},
205224
"project": {
@@ -341,9 +360,6 @@ func resourceCertificateManagerCertificateRead(d *schema.ResourceData, meta inte
341360
if err := d.Set("scope", flattenCertificateManagerCertificateScope(res["scope"], d, config)); err != nil {
342361
return fmt.Errorf("Error reading Certificate: %s", err)
343362
}
344-
if err := d.Set("self_managed", flattenCertificateManagerCertificateSelfManaged(res["selfManaged"], d, config)); err != nil {
345-
return fmt.Errorf("Error reading Certificate: %s", err)
346-
}
347363
if err := d.Set("managed", flattenCertificateManagerCertificateManaged(res["managed"], d, config)); err != nil {
348364
return fmt.Errorf("Error reading Certificate: %s", err)
349365
}
@@ -503,29 +519,6 @@ func flattenCertificateManagerCertificateScope(v interface{}, d *schema.Resource
503519
return v
504520
}
505521

506-
func flattenCertificateManagerCertificateSelfManaged(v interface{}, d *schema.ResourceData, config *Config) interface{} {
507-
if v == nil {
508-
return nil
509-
}
510-
original := v.(map[string]interface{})
511-
if len(original) == 0 {
512-
return nil
513-
}
514-
transformed := make(map[string]interface{})
515-
transformed["certificate_pem"] =
516-
flattenCertificateManagerCertificateSelfManagedCertificatePem(original["certificatePem"], d, config)
517-
transformed["private_key_pem"] =
518-
flattenCertificateManagerCertificateSelfManagedPrivateKeyPem(original["privateKeyPem"], d, config)
519-
return []interface{}{transformed}
520-
}
521-
func flattenCertificateManagerCertificateSelfManagedCertificatePem(v interface{}, d *schema.ResourceData, config *Config) interface{} {
522-
return v
523-
}
524-
525-
func flattenCertificateManagerCertificateSelfManagedPrivateKeyPem(v interface{}, d *schema.ResourceData, config *Config) interface{} {
526-
return v
527-
}
528-
529522
func flattenCertificateManagerCertificateManaged(v interface{}, d *schema.ResourceData, config *Config) interface{} {
530523
if v == nil {
531524
return nil
@@ -661,6 +654,20 @@ func expandCertificateManagerCertificateSelfManaged(v interface{}, d TerraformRe
661654
transformed["privateKeyPem"] = transformedPrivateKeyPem
662655
}
663656

657+
transformedPemCertificate, err := expandCertificateManagerCertificateSelfManagedPemCertificate(original["pem_certificate"], d, config)
658+
if err != nil {
659+
return nil, err
660+
} else if val := reflect.ValueOf(transformedPemCertificate); val.IsValid() && !isEmptyValue(val) {
661+
transformed["pemCertificate"] = transformedPemCertificate
662+
}
663+
664+
transformedPemPrivateKey, err := expandCertificateManagerCertificateSelfManagedPemPrivateKey(original["pem_private_key"], d, config)
665+
if err != nil {
666+
return nil, err
667+
} else if val := reflect.ValueOf(transformedPemPrivateKey); val.IsValid() && !isEmptyValue(val) {
668+
transformed["pemPrivateKey"] = transformedPemPrivateKey
669+
}
670+
664671
return transformed, nil
665672
}
666673

@@ -672,6 +679,14 @@ func expandCertificateManagerCertificateSelfManagedPrivateKeyPem(v interface{},
672679
return v, nil
673680
}
674681

682+
func expandCertificateManagerCertificateSelfManagedPemCertificate(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
683+
return v, nil
684+
}
685+
686+
func expandCertificateManagerCertificateSelfManagedPemPrivateKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
687+
return v, nil
688+
}
689+
675690
func expandCertificateManagerCertificateManaged(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
676691
l := v.([]interface{})
677692
if len(l) == 0 || l[0] == nil {

google-beta/resource_certificate_manager_certificate_generated_test.go

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
2424
)
2525

26-
func TestAccCertificateManagerCertificate_certificateManagerCertificateBasicExample(t *testing.T) {
26+
func TestAccCertificateManagerCertificate_certificateManagerSelfManagedCertificateExample(t *testing.T) {
2727
t.Parallel()
2828

2929
context := map[string]interface{}{
@@ -36,48 +36,29 @@ func TestAccCertificateManagerCertificate_certificateManagerCertificateBasicExam
3636
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
3737
Steps: []resource.TestStep{
3838
{
39-
Config: testAccCertificateManagerCertificate_certificateManagerCertificateBasicExample(context),
39+
Config: testAccCertificateManagerCertificate_certificateManagerSelfManagedCertificateExample(context),
4040
},
4141
{
4242
ResourceName: "google_certificate_manager_certificate.default",
4343
ImportState: true,
4444
ImportStateVerify: true,
45-
ImportStateVerifyIgnore: []string{"name", "managed.0.dns_authorizations"},
45+
ImportStateVerifyIgnore: []string{"self_managed", "name"},
4646
},
4747
},
4848
})
4949
}
5050

51-
func testAccCertificateManagerCertificate_certificateManagerCertificateBasicExample(context map[string]interface{}) string {
51+
func testAccCertificateManagerCertificate_certificateManagerSelfManagedCertificateExample(context map[string]interface{}) string {
5252
return Nprintf(`
5353
resource "google_certificate_manager_certificate" "default" {
54-
name = "tf-test-dns-cert%{random_suffix}"
54+
name = "tf-test-self-managed-cert%{random_suffix}"
5555
description = "The default cert"
5656
scope = "EDGE_CACHE"
57-
managed {
58-
domains = [
59-
google_certificate_manager_dns_authorization.instance.domain,
60-
google_certificate_manager_dns_authorization.instance2.domain,
61-
]
62-
dns_authorizations = [
63-
google_certificate_manager_dns_authorization.instance.id,
64-
google_certificate_manager_dns_authorization.instance2.id,
65-
]
57+
self_managed {
58+
pem_certificate = file("test-fixtures/certificatemanager/cert.pem")
59+
pem_private_key = file("test-fixtures/certificatemanager/private-key.pem")
6660
}
6761
}
68-
69-
70-
resource "google_certificate_manager_dns_authorization" "instance" {
71-
name = "tf-test-dns-auth%{random_suffix}"
72-
description = "The default dnss"
73-
domain = "subdomain%{random_suffix}.hashicorptest.com"
74-
}
75-
76-
resource "google_certificate_manager_dns_authorization" "instance2" {
77-
name = "tf-test-dns-auth2%{random_suffix}"
78-
description = "The default dnss"
79-
domain = "subdomain2%{random_suffix}.hashicorptest.com"
80-
}
8162
`, context)
8263
}
8364

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDDzCCAfegAwIBAgIUDOiCLH9QNMMYnjPZVf4VwO9blsEwDQYJKoZIhvcNAQEL
3+
BQAwFjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wIBcNMjIwODI0MDg0MDUxWhgPMzAy
4+
MTEyMjUwODQwNTFaMBYxFDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG
5+
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvOT925GG4lKV9HvAHsbecMhGPAqjhVRC26iZ
6+
UJC8oSWOu95lWJSX5ZhbiF6Nz192wDGV/VAh3Lxj8RYtcn75eDxQKTcKouDld+To
7+
CGIStPFWbR6rbysLuZqFVEXVOTvp2QIegInfrvnGC4j7Qpic7zrFB9HzJx+0HpeE
8+
yO4gkdzJfEK/gMmolUgJrKX59o+0+Rj+Jq3EtcQxL1fVBVJSx0NvpoR1eYpnHMr/
9+
rJKZkUUZ2xE86hrtpiP6OEYQTi00rmf4GnZF5QfGGD0xuoQXtR7Tu+XhKibXIhxc
10+
D4RzPLX1QS040PXvmMPLDb4YlUQ6V3Rs42JDvkkDwIMXZvn8awIDAQABo1MwUTAd
11+
BgNVHQ4EFgQURuo1CCZZAUv7xi02f2nC5tRbf18wHwYDVR0jBBgwFoAURuo1CCZZ
12+
AUv7xi02f2nC5tRbf18wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC
13+
AQEAqx3tDxurnYr9EUPhF5/LlDPYM+VI7EgrKdRnuIqUlZI0tm3vOGME0te6dBTC
14+
YLNaHLW3m/4Tm4M2eg0Kpz6CxJfn3109G31dCi0xwzSDHf5TPUWvqIVhq5WRgMIf
15+
n8KYBlQSmqdJBRztUIQH/UPFnSbxymlS4s5qwDgTH5ag9EEBcnWsQ2LZjKi0eqve
16+
MaqAvvB+j8RGZzYY4re94bSJI42zIZ6nMWPtXwRuDc30xl/u+E0jWIgWbPwSd6Km
17+
3wnJnGiU2ezPGq3zEU+Rc39VVIFKQpciNeYuF3neHPJvYOf58qW2Z8s0VH0MR1x3
18+
3DoO/e30FIr9j+PRD+s5BPKF2A==
19+
-----END CERTIFICATE-----
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC85P3bkYbiUpX0
3+
e8Aext5wyEY8CqOFVELbqJlQkLyhJY673mVYlJflmFuIXo3PX3bAMZX9UCHcvGPx
4+
Fi1yfvl4PFApNwqi4OV35OgIYhK08VZtHqtvKwu5moVURdU5O+nZAh6Aid+u+cYL
5+
iPtCmJzvOsUH0fMnH7Qel4TI7iCR3Ml8Qr+AyaiVSAmspfn2j7T5GP4mrcS1xDEv
6+
V9UFUlLHQ2+mhHV5imccyv+skpmRRRnbETzqGu2mI/o4RhBOLTSuZ/gadkXlB8YY
7+
PTG6hBe1HtO75eEqJtciHFwPhHM8tfVBLTjQ9e+Yw8sNvhiVRDpXdGzjYkO+SQPA
8+
gxdm+fxrAgMBAAECggEAV4/A24TQpV4KFBw/WSTvnRFBeXinB1mhamhztWR6hCrA
9+
SPcVPKQY632eRI8sJmpGxl3V/Ogl4khT/cA9jfstEl7G++v/WrRsupCaPLSVnlnX
10+
KdsTNgOauk1WK9P5PMA4rPcuA4Cl91riQpubeWn8KWsxRWg90i+Ak8PB8lBsOaB1
11+
QzjigWlrRWSpodaw0MBIMZFDL2BYK8HEr+wyATYIyGvDQc9zCnMQIQIZyEPYepLO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IVATE KEY-----

website/docs/r/certificate_manager_certificate.html.markdown

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,27 @@ Certificate represents a HTTP-reachable backend for a Certificate.
2424

2525

2626

27-
~> **Warning:** All arguments including `self_managed.certificate_pem` and `self_managed.private_key_pem` will be stored in the raw
27+
~> **Warning:** All arguments including `self_managed`, `self_managed.certificate_pem`, and `self_managed.private_key_pem` will be stored in the raw
2828
state as plain-text. [Read more about sensitive data in state](https://www.terraform.io/language/state/sensitive-data).
2929

3030
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
31-
<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">
31+
<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">
3232
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
3333
</a>
3434
</div>
35-
## Example Usage - Certificate Manager Certificate Basic
35+
## Example Usage - Certificate Manager Self Managed Certificate
3636

3737

3838
```hcl
3939
resource "google_certificate_manager_certificate" "default" {
40-
name = "dns-cert"
40+
name = "self-managed-cert"
4141
description = "The default cert"
4242
scope = "EDGE_CACHE"
43-
managed {
44-
domains = [
45-
google_certificate_manager_dns_authorization.instance.domain,
46-
google_certificate_manager_dns_authorization.instance2.domain,
47-
]
48-
dns_authorizations = [
49-
google_certificate_manager_dns_authorization.instance.id,
50-
google_certificate_manager_dns_authorization.instance2.id,
51-
]
43+
self_managed {
44+
pem_certificate = file("test-fixtures/certificatemanager/cert.pem")
45+
pem_private_key = file("test-fixtures/certificatemanager/private-key.pem")
5246
}
5347
}
54-
55-
56-
resource "google_certificate_manager_dns_authorization" "instance" {
57-
name = "dns-auth"
58-
description = "The default dnss"
59-
domain = "subdomain.hashicorptest.com"
60-
}
61-
62-
resource "google_certificate_manager_dns_authorization" "instance2" {
63-
name = "dns-auth2"
64-
description = "The default dnss"
65-
domain = "subdomain2.hashicorptest.com"
66-
}
6748
```
6849

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

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

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

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

114+
* `pem_certificate` -
115+
(Optional)
116+
The certificate chain in PEM-encoded form.
117+
Leaf certificate comes first, followed by intermediate ones if any.
118+
119+
* `pem_private_key` -
120+
(Optional)
121+
The private key of the leaf certificate in PEM-encoded form.
122+
132123
<a name="nested_managed"></a>The `managed` block supports:
133124

134125
* `domains` -

0 commit comments

Comments
 (0)