Skip to content

Commit 4fa2e11

Browse files
PrivateCA PR feedback (#4939) (#3411)
Co-authored-by: Riley Karson <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Riley Karson <[email protected]>
1 parent 4cd9fc2 commit 4fa2e11

10 files changed

+45
-67
lines changed

.changelog/4939.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/resource_privateca_ca_pool.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ If this is omitted, then this CaPool will not add restrictions on a certificate'
370370
Schema: map[string]*schema.Schema{
371371
"allow_subject_alt_names_passthrough": {
372372
Type: schema.TypeBool,
373-
Optional: true,
373+
Required: true,
374374
Description: `If this is set, the SubjectAltNames extension may be copied from a certificate request into the signed certificate.
375375
Otherwise, the requested SubjectAltNames will be discarded.`,
376376
},
377377
"allow_subject_passthrough": {
378378
Type: schema.TypeBool,
379-
Optional: true,
379+
Required: true,
380380
Description: `If this is set, the Subject field may be copied from a certificate request into the signed certificate.
381381
Otherwise, the requested Subject will be discarded.`,
382382
},
@@ -1160,14 +1160,14 @@ func expandPrivatecaCaPoolIssuancePolicyIdentityConstraints(v interface{}, d Ter
11601160
transformedAllowSubjectPassthrough, err := expandPrivatecaCaPoolIssuancePolicyIdentityConstraintsAllowSubjectPassthrough(original["allow_subject_passthrough"], d, config)
11611161
if err != nil {
11621162
return nil, err
1163-
} else if val := reflect.ValueOf(transformedAllowSubjectPassthrough); val.IsValid() && !isEmptyValue(val) {
1163+
} else {
11641164
transformed["allowSubjectPassthrough"] = transformedAllowSubjectPassthrough
11651165
}
11661166

11671167
transformedAllowSubjectAltNamesPassthrough, err := expandPrivatecaCaPoolIssuancePolicyIdentityConstraintsAllowSubjectAltNamesPassthrough(original["allow_subject_alt_names_passthrough"], d, config)
11681168
if err != nil {
11691169
return nil, err
1170-
} else if val := reflect.ValueOf(transformedAllowSubjectAltNamesPassthrough); val.IsValid() && !isEmptyValue(val) {
1170+
} else {
11711171
transformed["allowSubjectAltNamesPassthrough"] = transformedAllowSubjectAltNamesPassthrough
11721172
}
11731173

google-beta/resource_privateca_ca_pool_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ resource "google_privateca_ca_pool" "default" {
7777
maximum_lifetime = "50000s"
7878
allowed_issuance_modes {
7979
allow_csr_based_issuance = true
80-
allow_config_based_issuance = true
80+
allow_config_based_issuance = false
8181
}
8282
identity_constraints {
83-
allow_subject_passthrough = true
83+
allow_subject_passthrough = false
8484
allow_subject_alt_names_passthrough = true
8585
cel_expression {
8686
expression = "subject_alt_names.all(san, san.type == DNS || san.type == EMAIL )"
@@ -100,7 +100,7 @@ resource "google_privateca_ca_pool" "default" {
100100
object_id_path = [123, 888]
101101
}
102102
policy_ids {
103-
object_id_path = [456, 120]
103+
object_id_path = [2,5,29,25]
104104
}
105105
ca_options {
106106
is_ca = true

google-beta/resource_privateca_certificate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ running 'gcloud privateca locations list'.`,
8686
Required: true,
8787
ForceNew: true,
8888
ValidateFunc: validation.StringInSlice([]string{"KEY_TYPE_UNSPECIFIED", "PEM"}, false),
89-
Description: `Types of public keys that are supported. At a minimum, we support RSA, for the key sizes or curves listed: https://cloud.google.com/kms/docs/algorithms#asymmetric_signing_algorithms Possible values: ["KEY_TYPE_UNSPECIFIED", "PEM"]`,
89+
Description: `The format of the public key. Currently, only PEM format is supported. Possible values: ["KEY_TYPE_UNSPECIFIED", "PEM"]`,
9090
},
9191
"key": {
9292
Type: schema.TypeString,
@@ -701,7 +701,7 @@ fractional digits, terminated by 's'. Example: "3.5s".`,
701701
"format": {
702702
Type: schema.TypeString,
703703
Computed: true,
704-
Description: `Types of public keys that are supported. At a minimum, we support RSA, for the key sizes or curves listed: https://cloud.google.com/kms/docs/algorithms#asymmetric_signing_algorithms`,
704+
Description: `The format of the public key. Currently, only PEM format is supported.`,
705705
},
706706
"key": {
707707
Type: schema.TypeString,

google-beta/resource_privateca_certificate_authority.go

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ such as the CA certificate and CRLs. This must be a bucket name, without any pre
482482
my-bucket, you would simply specify 'my-bucket'. If not specified, a managed bucket will be
483483
created.`,
484484
},
485-
"ignore_active_certificates": {
485+
"ignore_active_certificates_on_deletion": {
486486
Type: schema.TypeBool,
487487
Optional: true,
488488
ForceNew: true,
@@ -509,16 +509,6 @@ An object containing a list of "key": value pairs. Example: { "name": "wrench",
509509
fractional digits, terminated by 's'. Example: "3.5s".`,
510510
Default: "315360000s",
511511
},
512-
"tier": {
513-
Type: schema.TypeString,
514-
Optional: true,
515-
ForceNew: true,
516-
ValidateFunc: validation.StringInSlice([]string{"ENTERPRISE", "DEVOPS", ""}, false),
517-
Description: `The Tier of this CertificateAuthority. 'ENTERPRISE' Certificate Authorities track
518-
server side certificates issued, and support certificate revocation. For more details,
519-
please check the [associated documentation](https://cloud.google.com/certificate-authority-service/docs/tiers). Default value: "ENTERPRISE" Possible values: ["ENTERPRISE", "DEVOPS"]`,
520-
Default: "ENTERPRISE",
521-
},
522512
"type": {
523513
Type: schema.TypeString,
524514
Optional: true,
@@ -615,12 +605,6 @@ func resourcePrivatecaCertificateAuthorityCreate(d *schema.ResourceData, meta in
615605
} else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
616606
obj["type"] = typeProp
617607
}
618-
tierProp, err := expandPrivatecaCertificateAuthorityTier(d.Get("tier"), d, config)
619-
if err != nil {
620-
return err
621-
} else if v, ok := d.GetOkExists("tier"); !isEmptyValue(reflect.ValueOf(tierProp)) && (ok || !reflect.DeepEqual(v, tierProp)) {
622-
obj["tier"] = tierProp
623-
}
624608
configProp, err := expandPrivatecaCertificateAuthorityConfig(d.Get("config"), d, config)
625609
if err != nil {
626610
return err
@@ -726,6 +710,13 @@ func resourcePrivatecaCertificateAuthorityCreate(d *schema.ResourceData, meta in
726710
return fmt.Errorf("Error enabling CertificateAuthority: %s", err)
727711
}
728712

713+
err = privatecaOperationWaitTimeWithResponse(
714+
config, res, &opRes, project, "Enabling CertificateAuthority", userAgent,
715+
d.Timeout(schema.TimeoutCreate))
716+
if err != nil {
717+
return fmt.Errorf("Error waiting to enable CertificateAuthority: %s", err)
718+
}
719+
729720
log.Printf("[DEBUG] Finished creating CertificateAuthority %q: %#v", d.Id(), res)
730721

731722
return resourcePrivatecaCertificateAuthorityRead(d, meta)
@@ -783,9 +774,6 @@ func resourcePrivatecaCertificateAuthorityRead(d *schema.ResourceData, meta inte
783774
if err := d.Set("type", flattenPrivatecaCertificateAuthorityType(res["type"], d, config)); err != nil {
784775
return fmt.Errorf("Error reading CertificateAuthority: %s", err)
785776
}
786-
if err := d.Set("tier", flattenPrivatecaCertificateAuthorityTier(res["tier"], d, config)); err != nil {
787-
return fmt.Errorf("Error reading CertificateAuthority: %s", err)
788-
}
789777
if err := d.Set("config", flattenPrivatecaCertificateAuthorityConfig(res["config"], d, config)); err != nil {
790778
return fmt.Errorf("Error reading CertificateAuthority: %s", err)
791779
}
@@ -835,7 +823,7 @@ func resourcePrivatecaCertificateAuthorityDelete(d *schema.ResourceData, meta in
835823
}
836824
billingProject = project
837825

838-
url, err := replaceVars(d, config, "{{PrivatecaBasePath}}projects/{{project}}/locations/{{location}}/caPools/{{pool}}/certificateAuthorities/{{certificate_authority_id}}?ignoreActiveCertificates={{ignore_active_certificates}}")
826+
url, err := replaceVars(d, config, "{{PrivatecaBasePath}}projects/{{project}}/locations/{{location}}/caPools/{{pool}}/certificateAuthorities/{{certificate_authority_id}}?ignoreActiveCertificates={{ignore_active_certificates_on_deletion}}")
839827
if err != nil {
840828
return err
841829
}
@@ -846,11 +834,18 @@ func resourcePrivatecaCertificateAuthorityDelete(d *schema.ResourceData, meta in
846834
return err
847835
}
848836

849-
log.Printf("[DEBUG] Enabling CertificateAuthority: %#v", obj)
837+
log.Printf("[DEBUG] Disabling CertificateAuthority: %#v", obj)
850838

851-
_, err = sendRequest(config, "POST", billingProject, disableUrl, userAgent, nil)
839+
res, err = sendRequest(config, "POST", billingProject, disableUrl, userAgent, nil)
852840
if err != nil {
853-
return fmt.Errorf("Error enabling CertificateAuthority: %s", err)
841+
return fmt.Errorf("Error disabling CertificateAuthority: %s", err)
842+
}
843+
844+
err = privatecaOperationWaitTimeWithResponse(
845+
config, res, &opRes, project, "Disabling CertificateAuthority", userAgent,
846+
d.Timeout(schema.TimeoutDelete))
847+
if err != nil {
848+
return fmt.Errorf("Error waiting to disable CertificateAuthority: %s", err)
854849
}
855850
log.Printf("[DEBUG] Deleting CertificateAuthority %q", d.Id())
856851

@@ -904,10 +899,6 @@ func flattenPrivatecaCertificateAuthorityType(v interface{}, d *schema.ResourceD
904899
return v
905900
}
906901

907-
func flattenPrivatecaCertificateAuthorityTier(v interface{}, d *schema.ResourceData, config *Config) interface{} {
908-
return v
909-
}
910-
911902
func flattenPrivatecaCertificateAuthorityConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
912903
if v == nil {
913904
return nil
@@ -1129,10 +1120,6 @@ func expandPrivatecaCertificateAuthorityType(v interface{}, d TerraformResourceD
11291120
return v, nil
11301121
}
11311122

1132-
func expandPrivatecaCertificateAuthorityTier(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1133-
return v, nil
1134-
}
1135-
11361123
func expandPrivatecaCertificateAuthorityConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
11371124
l := v.([]interface{})
11381125
if len(l) == 0 || l[0] == nil {

google-beta/resource_privateca_certificate_authority_generated_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityBasicExam
4343
ResourceName: "google_privateca_certificate_authority.default",
4444
ImportState: true,
4545
ImportStateVerify: true,
46-
ImportStateVerifyIgnore: []string{"ignore_active_certificates", "location", "certificate_authority_id", "pool"},
46+
ImportStateVerifyIgnore: []string{"ignore_active_certificates_on_deletion", "location", "certificate_authority_id", "pool"},
4747
},
4848
},
4949
})
@@ -101,7 +101,7 @@ resource "google_privateca_certificate_authority" "default" {
101101
`, context)
102102
}
103103

104-
func TestAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityCmekExample(t *testing.T) {
104+
func TestAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityByoKeyExample(t *testing.T) {
105105
skipIfVcr(t)
106106
t.Parallel()
107107

@@ -117,19 +117,19 @@ func TestAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityCmekExamp
117117
CheckDestroy: testAccCheckPrivatecaCertificateAuthorityDestroyProducer(t),
118118
Steps: []resource.TestStep{
119119
{
120-
Config: testAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityCmekExample(context),
120+
Config: testAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityByoKeyExample(context),
121121
},
122122
{
123123
ResourceName: "google_privateca_certificate_authority.default",
124124
ImportState: true,
125125
ImportStateVerify: true,
126-
ImportStateVerifyIgnore: []string{"ignore_active_certificates", "location", "certificate_authority_id", "pool"},
126+
ImportStateVerifyIgnore: []string{"ignore_active_certificates_on_deletion", "location", "certificate_authority_id", "pool"},
127127
},
128128
},
129129
})
130130
}
131131

132-
func testAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityCmekExample(context map[string]interface{}) string {
132+
func testAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityByoKeyExample(context map[string]interface{}) string {
133133
return Nprintf(`
134134
resource "google_project_service_identity" "privateca_sa" {
135135
service = "privateca.googleapis.com"

google-beta/resource_privateca_certificate_generated_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ resource "google_privateca_certificate_authority" "test-ca" {
5656
certificate_authority_id = "tf-test-my-certificate-authority%{random_suffix}"
5757
location = "us-central1"
5858
pool = "%{pool}"
59-
tier = "ENTERPRISE"
60-
ignore_active_certificates = true
59+
ignore_active_certificates_on_deletion = true
6160
config {
6261
subject_config {
6362
subject {
@@ -167,7 +166,6 @@ resource "google_privateca_certificate_authority" "test-ca" {
167166
pool = "%{pool}"
168167
certificate_authority_id = "tf-test-my-certificate-authority%{random_suffix}"
169168
location = "us-central1"
170-
tier = "ENTERPRISE"
171169
config {
172170
subject_config {
173171
subject {

website/docs/r/privateca_ca_pool.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ The `allowed_issuance_modes` block supports:
259259
The `identity_constraints` block supports:
260260

261261
* `allow_subject_passthrough` -
262-
(Optional)
262+
(Required)
263263
If this is set, the Subject field may be copied from a certificate request into the signed certificate.
264264
Otherwise, the requested Subject will be discarded.
265265

266266
* `allow_subject_alt_names_passthrough` -
267-
(Optional)
267+
(Required)
268268
If this is set, the SubjectAltNames extension may be copied from a certificate request into the signed certificate.
269269
Otherwise, the requested SubjectAltNames will be discarded.
270270

website/docs/r/privateca_certificate.html.markdown

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ resource "google_privateca_certificate_authority" "test-ca" {
4343
certificate_authority_id = "my-certificate-authority"
4444
location = "us-central1"
4545
pool = ""
46-
tier = "ENTERPRISE"
47-
ignore_active_certificates = true
46+
ignore_active_certificates_on_deletion = true
4847
config {
4948
subject_config {
5049
subject {
@@ -132,7 +131,6 @@ resource "google_privateca_certificate_authority" "test-ca" {
132131
pool = ""
133132
certificate_authority_id = "my-certificate-authority"
134133
location = "us-central1"
135-
tier = "ENTERPRISE"
136134
config {
137135
subject_config {
138136
subject {
@@ -563,7 +561,7 @@ The `public_key` block supports:
563561

564562
* `format` -
565563
(Required)
566-
Types of public keys that are supported. At a minimum, we support RSA, for the key sizes or curves listed: https://cloud.google.com/kms/docs/algorithms#asymmetric_signing_algorithms
564+
The format of the public key. Currently, only PEM format is supported.
567565
Possible values are `KEY_TYPE_UNSPECIFIED` and `PEM`.
568566

569567
## Attributes Reference
@@ -819,7 +817,7 @@ The `public_key` block contains:
819817
Required. A public key. When this is specified in a request, the padding and encoding can be any of the options described by the respective 'KeyType' value. When this is generated by the service, it will always be an RFC 5280 SubjectPublicKeyInfo structure containing an algorithm identifier and a key. A base64-encoded string.
820818

821819
* `format` -
822-
Types of public keys that are supported. At a minimum, we support RSA, for the key sizes or curves listed: https://cloud.google.com/kms/docs/algorithms#asymmetric_signing_algorithms
820+
The format of the public key. Currently, only PEM format is supported.
823821

824822
The `subject_key_id` block contains:
825823

website/docs/r/privateca_certificate_authority.html.markdown

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ resource "google_privateca_certificate_authority" "default" {
9090
}
9191
```
9292
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
93-
<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=privateca_certificate_authority_cmek&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
93+
<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=privateca_certificate_authority_byo_key&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
9494
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
9595
</a>
9696
</div>
97-
## Example Usage - Privateca Certificate Authority Cmek
97+
## Example Usage - Privateca Certificate Authority Byo Key
9898

9999

100100
```hcl
@@ -445,7 +445,7 @@ The `key_spec` block supports:
445445
- - -
446446

447447

448-
* `ignore_active_certificates` -
448+
* `ignore_active_certificates_on_deletion` -
449449
(Optional)
450450
This field allows the CA to be deleted even if the CA has active certs. Active certs include both unrevoked and unexpired certs.
451451
Use with care. Defaults to `false`.
@@ -459,14 +459,6 @@ The `key_spec` block supports:
459459
Default value is `SELF_SIGNED`.
460460
Possible values are `SELF_SIGNED` and `SUBORDINATE`.
461461

462-
* `tier` -
463-
(Optional)
464-
The Tier of this CertificateAuthority. `ENTERPRISE` Certificate Authorities track
465-
server side certificates issued, and support certificate revocation. For more details,
466-
please check the [associated documentation](https://cloud.google.com/certificate-authority-service/docs/tiers).
467-
Default value is `ENTERPRISE`.
468-
Possible values are `ENTERPRISE` and `DEVOPS`.
469-
470462
* `lifetime` -
471463
(Optional)
472464
The desired lifetime of the CA certificate. Used to create the "notBeforeTime" and

0 commit comments

Comments
 (0)