-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misc improvements for Certificate Authority #4407
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to verify: this needs to be set to a fixed project number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The API takes both a project number or project ID (the corresponding project ID for that project number is
privateca-data
), however the read call will always answer with the project number. So the point of passing the project number directly (instead of project ID) was to avoid a permadiff. But now that we have this custom encoder and the corresponding diff suppress function, we could pass the project ID itself since the diff suppress would only look into the suffix (the reusable config itself) when the user specifies only the short form. Would you prefer to have the project ID on the create call to make this more legible?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I've seen that behavior in other APIs as well. I think it is fine as is, especially when the comment above clarifies the Google-managed project part. Thanks for explaining.