Skip to content

Commit 6f4cbaf

Browse files
modular-magicianHamza Hassan
and
Hamza Hassan
authored
Add issuanceConfig property to managed certificates (#8276) (#15101)
* Add issuanceConfig property to managed certificates * Remove trailing spaces in Certificate.yaml --------- Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Hamza Hassan <[email protected]>
1 parent 19a1256 commit 6f4cbaf

File tree

4 files changed

+228
-7
lines changed

4 files changed

+228
-7
lines changed

.changelog/8276.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
certificatemanager: added `issuance_config` field to `google_certificate_manager_certificate` resource
3+
```

google/resource_certificate_manager_certificate_generated_test.go

+106-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
3131
)
3232

33-
func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateExample(t *testing.T) {
33+
func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateDnsExample(t *testing.T) {
3434
t.Parallel()
3535

3636
context := map[string]interface{}{
@@ -43,7 +43,7 @@ func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedCertifi
4343
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
4444
Steps: []resource.TestStep{
4545
{
46-
Config: testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateExample(context),
46+
Config: testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateDnsExample(context),
4747
},
4848
{
4949
ResourceName: "google_certificate_manager_certificate.default",
@@ -55,7 +55,7 @@ func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedCertifi
5555
})
5656
}
5757

58-
func testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateExample(context map[string]interface{}) string {
58+
func testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateDnsExample(context map[string]interface{}) string {
5959
return acctest.Nprintf(`
6060
resource "google_certificate_manager_certificate" "default" {
6161
name = "tf-test-dns-cert%{random_suffix}"
@@ -88,6 +88,109 @@ resource "google_certificate_manager_dns_authorization" "instance2" {
8888
`, context)
8989
}
9090

91+
func TestAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateIssuanceConfigExample(t *testing.T) {
92+
t.Parallel()
93+
94+
context := map[string]interface{}{
95+
"random_suffix": acctest.RandString(t, 10),
96+
}
97+
98+
acctest.VcrTest(t, resource.TestCase{
99+
PreCheck: func() { acctest.AccTestPreCheck(t) },
100+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
101+
CheckDestroy: testAccCheckCertificateManagerCertificateDestroyProducer(t),
102+
Steps: []resource.TestStep{
103+
{
104+
Config: testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateIssuanceConfigExample(context),
105+
},
106+
{
107+
ResourceName: "google_certificate_manager_certificate.default",
108+
ImportState: true,
109+
ImportStateVerify: true,
110+
ImportStateVerifyIgnore: []string{"self_managed", "name", "location"},
111+
},
112+
},
113+
})
114+
}
115+
116+
func testAccCertificateManagerCertificate_certificateManagerGoogleManagedCertificateIssuanceConfigExample(context map[string]interface{}) string {
117+
return acctest.Nprintf(`
118+
resource "google_certificate_manager_certificate" "default" {
119+
name = "tf-test-issuance-config-cert%{random_suffix}"
120+
description = "The default cert"
121+
scope = "EDGE_CACHE"
122+
managed {
123+
domains = [
124+
"terraform.subdomain1.com"
125+
]
126+
issuance_config = google_certificate_manager_certificate_issuance_config.issuanceconfig.id
127+
}
128+
}
129+
130+
131+
132+
# creating certificate_issuance_config to use it in the managed certificate
133+
resource "google_certificate_manager_certificate_issuance_config" "issuanceconfig" {
134+
name = "issuanceconfigtestterraform"
135+
description = "sample description for the certificate issuanceConfigs"
136+
certificate_authority_config {
137+
certificate_authority_service_config {
138+
ca_pool = google_privateca_ca_pool.pool.id
139+
}
140+
}
141+
lifetime = "1814400s"
142+
rotation_window_percentage = 34
143+
key_algorithm = "ECDSA_P256"
144+
depends_on=[google_privateca_certificate_authority.ca_authority]
145+
}
146+
147+
resource "google_privateca_ca_pool" "pool" {
148+
name = "tf-test-my-ca-pool%{random_suffix}"
149+
location = "us-central1"
150+
tier = "ENTERPRISE"
151+
}
152+
153+
resource "google_privateca_certificate_authority" "ca_authority" {
154+
location = "us-central1"
155+
pool = google_privateca_ca_pool.pool.name
156+
certificate_authority_id = "tf-test-my-ca%{random_suffix}"
157+
config {
158+
subject_config {
159+
subject {
160+
organization = "HashiCorp"
161+
common_name = "my-certificate-authority"
162+
}
163+
subject_alt_name {
164+
dns_names = ["hashicorp.com"]
165+
}
166+
}
167+
x509_config {
168+
ca_options {
169+
is_ca = true
170+
}
171+
key_usage {
172+
base_key_usage {
173+
cert_sign = true
174+
crl_sign = true
175+
}
176+
extended_key_usage {
177+
server_auth = true
178+
}
179+
}
180+
}
181+
}
182+
key_spec {
183+
algorithm = "RSA_PKCS1_4096_SHA256"
184+
}
185+
186+
// Disable CA deletion related safe checks for easier cleanup.
187+
deletion_protection = false
188+
skip_grace_period = true
189+
ignore_active_certificates_on_deletion = true
190+
}
191+
`, context)
192+
}
193+
91194
func TestAccCertificateManagerCertificate_certificateManagerSelfManagedCertificateExample(t *testing.T) {
92195
t.Parallel()
93196

google/services/certificatemanager/resource_certificate_manager_certificate.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ automatically, for as long as it's authorized to do so.`,
106106
Optional: true,
107107
ForceNew: true,
108108
DiffSuppressFunc: tpgresource.ProjectNumberDiffSuppress,
109-
Description: `Authorizations that will be used for performing domain authorization`,
109+
Description: `Authorizations that will be used for performing domain authorization. Either issuanceConfig or dnsAuthorizations should be specificed, but not both.`,
110110
Elem: &schema.Schema{
111111
Type: schema.TypeString,
112112
},
@@ -121,6 +121,15 @@ Wildcard domains are only supported with DNS challenge resolution`,
121121
Type: schema.TypeString,
122122
},
123123
},
124+
"issuance_config": {
125+
Type: schema.TypeString,
126+
Optional: true,
127+
ForceNew: true,
128+
DiffSuppressFunc: tpgresource.CompareResourceNames,
129+
Description: `The resource name for a CertificateIssuanceConfig used to configure private PKI certificates in the format projects/*/locations/*/certificateIssuanceConfigs/*.
130+
If this field is not set, the certificates will instead be publicly signed as documented at https://cloud.google.com/load-balancing/docs/ssl-certificates/google-managed-certs#caa.
131+
Either issuanceConfig or dnsAuthorizations should be specificed, but not both.`,
132+
},
124133
"authorization_attempt_info": {
125134
Type: schema.TypeList,
126135
Computed: true,
@@ -590,6 +599,8 @@ func flattenCertificateManagerCertificateManaged(v interface{}, d *schema.Resour
590599
flattenCertificateManagerCertificateManagedDomains(original["domains"], d, config)
591600
transformed["dns_authorizations"] =
592601
flattenCertificateManagerCertificateManagedDnsAuthorizations(original["dnsAuthorizations"], d, config)
602+
transformed["issuance_config"] =
603+
flattenCertificateManagerCertificateManagedIssuanceConfig(original["issuanceConfig"], d, config)
593604
transformed["state"] =
594605
flattenCertificateManagerCertificateManagedState(original["state"], d, config)
595606
transformed["provisioning_issue"] =
@@ -606,6 +617,10 @@ func flattenCertificateManagerCertificateManagedDnsAuthorizations(v interface{},
606617
return v
607618
}
608619

620+
func flattenCertificateManagerCertificateManagedIssuanceConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
621+
return v
622+
}
623+
609624
func flattenCertificateManagerCertificateManagedState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
610625
return v
611626
}
@@ -768,6 +783,13 @@ func expandCertificateManagerCertificateManaged(v interface{}, d tpgresource.Ter
768783
transformed["dnsAuthorizations"] = transformedDnsAuthorizations
769784
}
770785

786+
transformedIssuanceConfig, err := expandCertificateManagerCertificateManagedIssuanceConfig(original["issuance_config"], d, config)
787+
if err != nil {
788+
return nil, err
789+
} else if val := reflect.ValueOf(transformedIssuanceConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) {
790+
transformed["issuanceConfig"] = transformedIssuanceConfig
791+
}
792+
771793
transformedState, err := expandCertificateManagerCertificateManagedState(original["state"], d, config)
772794
if err != nil {
773795
return nil, err
@@ -800,6 +822,10 @@ func expandCertificateManagerCertificateManagedDnsAuthorizations(v interface{},
800822
return v, nil
801823
}
802824

825+
func expandCertificateManagerCertificateManagedIssuanceConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
826+
return v, nil
827+
}
828+
803829
func expandCertificateManagerCertificateManagedState(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
804830
return v, nil
805831
}

website/docs/r/certificate_manager_certificate.html.markdown

+92-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ values will be stored in the raw state as plain text: `self_managed.certificate_
2828
[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.jpy.wang%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">
31+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=certificate_manager_google_managed_certificate_dns&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 Google Managed Certificate
35+
## Example Usage - Certificate Manager Google Managed Certificate Dns
3636

3737

3838
```hcl
@@ -65,6 +65,89 @@ resource "google_certificate_manager_dns_authorization" "instance2" {
6565
domain = "subdomain2.hashicorptest.com"
6666
}
6767
```
68+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
69+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=certificate_manager_google_managed_certificate_issuance_config&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
70+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
71+
</a>
72+
</div>
73+
## Example Usage - Certificate Manager Google Managed Certificate Issuance Config
74+
75+
76+
```hcl
77+
resource "google_certificate_manager_certificate" "default" {
78+
name = "issuance-config-cert"
79+
description = "The default cert"
80+
scope = "EDGE_CACHE"
81+
managed {
82+
domains = [
83+
"terraform.subdomain1.com"
84+
]
85+
issuance_config = google_certificate_manager_certificate_issuance_config.issuanceconfig.id
86+
}
87+
}
88+
89+
90+
91+
# creating certificate_issuance_config to use it in the managed certificate
92+
resource "google_certificate_manager_certificate_issuance_config" "issuanceconfig" {
93+
name = "issuanceconfigtestterraform"
94+
description = "sample description for the certificate issuanceConfigs"
95+
certificate_authority_config {
96+
certificate_authority_service_config {
97+
ca_pool = google_privateca_ca_pool.pool.id
98+
}
99+
}
100+
lifetime = "1814400s"
101+
rotation_window_percentage = 34
102+
key_algorithm = "ECDSA_P256"
103+
depends_on=[google_privateca_certificate_authority.ca_authority]
104+
}
105+
106+
resource "google_privateca_ca_pool" "pool" {
107+
name = "my-ca-pool"
108+
location = "us-central1"
109+
tier = "ENTERPRISE"
110+
}
111+
112+
resource "google_privateca_certificate_authority" "ca_authority" {
113+
location = "us-central1"
114+
pool = google_privateca_ca_pool.pool.name
115+
certificate_authority_id = "my-ca"
116+
config {
117+
subject_config {
118+
subject {
119+
organization = "HashiCorp"
120+
common_name = "my-certificate-authority"
121+
}
122+
subject_alt_name {
123+
dns_names = ["hashicorp.com"]
124+
}
125+
}
126+
x509_config {
127+
ca_options {
128+
is_ca = true
129+
}
130+
key_usage {
131+
base_key_usage {
132+
cert_sign = true
133+
crl_sign = true
134+
}
135+
extended_key_usage {
136+
server_auth = true
137+
}
138+
}
139+
}
140+
}
141+
key_spec {
142+
algorithm = "RSA_PKCS1_4096_SHA256"
143+
}
144+
145+
// Disable CA deletion related safe checks for easier cleanup.
146+
deletion_protection = false
147+
skip_grace_period = true
148+
ignore_active_certificates_on_deletion = true
149+
}
150+
```
68151
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
69152
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%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">
70153
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -190,7 +273,13 @@ The following arguments are supported:
190273

191274
* `dns_authorizations` -
192275
(Optional)
193-
Authorizations that will be used for performing domain authorization
276+
Authorizations that will be used for performing domain authorization. Either issuanceConfig or dnsAuthorizations should be specificed, but not both.
277+
278+
* `issuance_config` -
279+
(Optional)
280+
The resource name for a CertificateIssuanceConfig used to configure private PKI certificates in the format projects/*/locations/*/certificateIssuanceConfigs/*.
281+
If this field is not set, the certificates will instead be publicly signed as documented at https://cloud.google.com/load-balancing/docs/ssl-certificates/google-managed-certs#caa.
282+
Either issuanceConfig or dnsAuthorizations should be specificed, but not both.
194283

195284
* `state` -
196285
(Output)

0 commit comments

Comments
 (0)