@@ -122,6 +122,33 @@ func TestAccPrivatecaCertificateAuthority_rootCaManageDesiredState(t *testing.T)
122
122
})
123
123
}
124
124
125
+ func TestAccPrivatecaCertificateAuthority_subordinateCaActivatedByFirstPartyIssuerOnCreation (t * testing.T ) {
126
+ t .Parallel ()
127
+ acctest .SkipIfVcr (t )
128
+
129
+ random_suffix := acctest .RandString (t , 10 )
130
+ context := map [string ]interface {}{
131
+ "root_location" : "us-central1" ,
132
+ "sub_location" : "australia-southeast1" ,
133
+ "random_suffix" : random_suffix ,
134
+ }
135
+
136
+ resourceName := "google_privateca_certificate_authority.sub-1"
137
+ acctest .VcrTest (t , resource.TestCase {
138
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
139
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
140
+ CheckDestroy : testAccCheckPrivatecaCertificateAuthorityDestroyProducer (t ),
141
+ Steps : []resource.TestStep {
142
+ {
143
+ Config : testAccPrivatecaCertificateAuthority_privatecaCertificateAuthoritySubordinateWithFirstPartyIssuer (context ),
144
+ Check : resource .ComposeTestCheckFunc (
145
+ resource .TestCheckResourceAttr (resourceName , "state" , "ENABLED" ),
146
+ ),
147
+ },
148
+ },
149
+ })
150
+ }
151
+
125
152
func testAccPrivatecaCertificateAuthority_privatecaCertificateAuthorityBasicRoot (context map [string ]interface {}) string {
126
153
return acctest .Nprintf (`
127
154
resource "google_privateca_certificate_authority" "default" {
@@ -287,3 +314,139 @@ resource "google_privateca_certificate_authority" "default" {
287
314
}
288
315
` , context )
289
316
}
317
+
318
+ // testAccPrivatecaCertificateAuthority_privatecaCertificateAuthoritySubordinateWithFirstPartyIssuer provides a config
319
+ // which contains
320
+ // * A CaPool for root CA
321
+ // * A root CA
322
+ // * A CaPool for sub CA
323
+ // * A subordinate CA which should be activated by the above root CA
324
+ func testAccPrivatecaCertificateAuthority_privatecaCertificateAuthoritySubordinateWithFirstPartyIssuer (context map [string ]interface {}) string {
325
+ return acctest .Nprintf (`
326
+ resource "google_privateca_ca_pool" "root-pool" {
327
+ name = "root-pool-%{random_suffix}"
328
+ location = "%{root_location}"
329
+ tier = "ENTERPRISE"
330
+ publishing_options {
331
+ publish_ca_cert = true
332
+ publish_crl = true
333
+ }
334
+ }
335
+
336
+ resource "google_privateca_certificate_authority" "root-1" {
337
+ pool = google_privateca_ca_pool.root-pool.name
338
+ certificate_authority_id = "tf-test-my-certificate-authority-root-%{random_suffix}"
339
+ location = "%{root_location}"
340
+ config {
341
+ subject_config {
342
+ subject {
343
+ organization = "HashiCorp"
344
+ common_name = "my-certificate-authority"
345
+ }
346
+ subject_alt_name {
347
+ dns_names = ["hashicorp.com"]
348
+ }
349
+ }
350
+ x509_config {
351
+ ca_options {
352
+ is_ca = true
353
+ max_issuer_path_length = 10
354
+ }
355
+ key_usage {
356
+ base_key_usage {
357
+ digital_signature = true
358
+ content_commitment = true
359
+ key_encipherment = false
360
+ data_encipherment = true
361
+ key_agreement = true
362
+ cert_sign = true
363
+ crl_sign = true
364
+ decipher_only = true
365
+ }
366
+ extended_key_usage {
367
+ server_auth = true
368
+ client_auth = false
369
+ email_protection = true
370
+ code_signing = true
371
+ time_stamping = true
372
+ }
373
+ }
374
+ }
375
+ }
376
+ lifetime = "86400s"
377
+ key_spec {
378
+ algorithm = "RSA_PKCS1_4096_SHA256"
379
+ }
380
+
381
+ // Disable CA deletion related safe checks for easier cleanup.
382
+ deletion_protection = false
383
+ skip_grace_period = true
384
+ ignore_active_certificates_on_deletion = true
385
+ }
386
+
387
+ resource "google_privateca_ca_pool" "sub-pool" {
388
+ name = "sub-pool-%{random_suffix}"
389
+ location = "%{sub_location}"
390
+ tier = "ENTERPRISE"
391
+ publishing_options {
392
+ publish_ca_cert = true
393
+ publish_crl = true
394
+ }
395
+ }
396
+
397
+ resource "google_privateca_certificate_authority" "sub-1" {
398
+ pool = google_privateca_ca_pool.sub-pool.name
399
+ certificate_authority_id = "tf-test-my-certificate-authority-sub-%{random_suffix}"
400
+ location = "%{sub_location}"
401
+ subordinate_config {
402
+ certificate_authority = google_privateca_certificate_authority.root-1.name
403
+ }
404
+ config {
405
+ subject_config {
406
+ subject {
407
+ organization = "HashiCorp"
408
+ common_name = "my-certificate-authority"
409
+ }
410
+ subject_alt_name {
411
+ dns_names = ["hashicorp.com"]
412
+ }
413
+ }
414
+ x509_config {
415
+ ca_options {
416
+ is_ca = true
417
+ max_issuer_path_length = 10
418
+ }
419
+ key_usage {
420
+ base_key_usage {
421
+ digital_signature = true
422
+ content_commitment = true
423
+ key_encipherment = false
424
+ data_encipherment = true
425
+ key_agreement = true
426
+ cert_sign = true
427
+ crl_sign = true
428
+ decipher_only = true
429
+ }
430
+ extended_key_usage {
431
+ server_auth = true
432
+ client_auth = false
433
+ email_protection = true
434
+ code_signing = true
435
+ time_stamping = true
436
+ }
437
+ }
438
+ }
439
+ }
440
+ lifetime = "86400s"
441
+ key_spec {
442
+ algorithm = "RSA_PKCS1_4096_SHA256"
443
+ }
444
+ type = "SUBORDINATE"
445
+
446
+ // Disable CA deletion related safe checks for easier cleanup.
447
+ deletion_protection = false
448
+ skip_grace_period = true
449
+ ignore_active_certificates_on_deletion = true
450
+ }
451
+ ` , context )
452
+ }
0 commit comments