-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Misc improvements for Certificate Authority (#4407)
- Loading branch information
Showing
9 changed files
with
192 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
templates/terraform/constants/certificate_authority.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
func certificateAuthorityReusableConfigDiffSuppress(k, old, new string, d *schema.ResourceData) bool { | ||
if old != "" && new != "" { | ||
newParts := strings.Split(new, "/") | ||
// If the new form is a short version, we just | ||
// check if it matches the suffix of the old version | ||
if len(newParts) == 1 { | ||
return strings.HasSuffix(old, new) | ||
} | ||
} | ||
return old == new | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
rc := d.Get("config.0.reusable_config.0.reusable_config").(string) | ||
|
||
parts := strings.Split(rc, "/") | ||
|
||
if len(parts) == 1 { | ||
// If we have a short form: add the full path to the reusable-configs from | ||
// the Google-managed project and the location of the CA. | ||
config := obj["config"].(map[string]interface{}) | ||
configReusableConfig := config["reusableConfig"].(map[string]interface{}) | ||
configReusableConfig["reusableConfig"] = fmt.Sprintf("projects/568668481468/locations/%s/reusableConfigs/%s", d.Get("location"), parts[0]) | ||
} | ||
|
||
return obj, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
templates/terraform/examples/privateca_certificate_authority_cmek.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
resource "google_project_service_identity" "privateca_sa" { | ||
provider = google-beta | ||
service = "privateca.googleapis.com" | ||
} | ||
|
||
resource "google_kms_crypto_key_iam_binding" "privateca_sa_keyuser" { | ||
provider = google-beta | ||
crypto_key_id = "<%= ctx[:vars]['kms_key_name'] %>" | ||
role = "roles/cloudkms.signerVerifier" | ||
|
||
members = [ | ||
"serviceAccount:${google_project_service_identity.privateca_sa.email}", | ||
] | ||
} | ||
|
||
resource "google_privateca_certificate_authority" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
certificate_authority_id = "tf-test%{random_suffix}" | ||
location = "us-central1" | ||
|
||
key_spec { | ||
cloud_kms_key_version = "<%= ctx[:vars]['kms_key_name'] %>/cryptoKeyVersions/1" | ||
} | ||
|
||
config { | ||
subject_config { | ||
common_name = "Example Authority" | ||
subject { | ||
organization = "Example, Org." | ||
} | ||
} | ||
|
||
reusable_config { | ||
reusable_config= "root-unconstrained" | ||
} | ||
} | ||
|
||
depends_on = [ | ||
google_kms_crypto_key_iam_binding.privateca_sa_keyuser, | ||
] | ||
|
||
disable_on_delete = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
templates/terraform/iam/example_config_body/privateca_certificate_authority.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
certificate_authority = google_privateca_certificate_authority.default.id |
26 changes: 14 additions & 12 deletions
26
templates/terraform/pre_delete/privateca_certificate_authority.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
log.Printf("[DEBUG] Disabling CertificateAuthority %q", d.Id()) | ||
if d.Get("disable_on_delete").(bool) && d.Get("state").(string) == "ENABLED" { | ||
log.Printf("[DEBUG] Disabling CertificateAuthority %q", d.Id()) | ||
|
||
disableURL, err := replaceVars(d, config, "{{PrivatecaBasePath}}{{name}}:disable") | ||
if err != nil { | ||
return err | ||
} | ||
disableURL, err := replaceVars(d, config, "{{PrivatecaBasePath}}{{name}}:disable") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
disableRes, err := sendRequestWithTimeout(config, "POST", billingProject, disableURL, userAgent, obj, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil { | ||
return err | ||
} | ||
disableRes, err := sendRequestWithTimeout(config, "POST", billingProject, disableURL, userAgent, obj, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = privatecaOperationWaitTime(config, disableRes, project, "Disabling CertificateAuthority", userAgent, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil { | ||
return err | ||
err = privatecaOperationWaitTime(config, disableRes, project, "Disabling CertificateAuthority", userAgent, d.Timeout(schema.TimeoutDelete)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|