forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ceritificateManagerCertificates field to ComputeRegionTargetHttps…
…Proxy resource (GoogleCloudPlatform#10011) Co-authored-by: Hamza Hassan <[email protected]>
- Loading branch information
1 parent
4adec15
commit d4885da
Showing
4 changed files
with
83 additions
and
4 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
15 changes: 15 additions & 0 deletions
15
mmv1/templates/terraform/decoders/compute_region_target_https_proxy.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,15 @@ | ||
// Since both sslCertificates and certificateManagerCertificates maps to the same API field (sslCertificates), we need to check the types | ||
// of certificates that exist in the array and decide whether to change the field to certificateManagerCertificate or not. | ||
// The decoder logic depends on the fact that the API does not allow mixed type of certificates and it returns | ||
// certificate manager certificates in the format of //certificatemanager.googleapis.com/projects/*/locations/*/certificates/* | ||
if sslCertificates, ok := res["sslCertificates"].([]interface{}); ok && len(sslCertificates) > 0 { | ||
regPat, _ := regexp.Compile("//certificatemanager.googleapis.com/projects/(.*)/locations/(.*)/certificates/(.*)") | ||
|
||
if regPat.MatchString(sslCertificates[0].(string)) { | ||
// It is enough to check only the type of one of the provided certificates beacuse all the certificates should be the same type. | ||
log.Printf("[DEBUG] The field sslCertificates contains certificateManagerCertificates, the field name will be converted to certificateManagerCertificates") | ||
res["certificateManagerCertificates"] = res["sslCertificates"] | ||
delete(res, "sslCertificates") | ||
} | ||
} | ||
return res, nil |
10 changes: 10 additions & 0 deletions
10
mmv1/templates/terraform/encoders/compute_region_target_https_proxy.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,10 @@ | ||
|
||
if _, ok := obj["certificateManagerCertificates"]; ok { | ||
// The field certificateManagerCertificates should not be included in the API request, and it should be renamed to `sslCertificates` | ||
// The API does not allow using both certificate manager certificates and sslCertificates. If that changes | ||
// in the future, the encoder logic should change accordingly because this will mean that both fields are no longer mutual exclusive. | ||
log.Printf("[DEBUG] converting the field CertificateManagerCertificates to sslCertificates before sending the request") | ||
obj["sslCertificates"] = obj["certificateManagerCertificates"] | ||
delete(obj, "certificateManagerCertificates") | ||
} | ||
return obj, nil |
28 changes: 28 additions & 0 deletions
28
...lates/terraform/examples/region_target_https_proxy_certificate_manager_certificate.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,28 @@ | ||
resource "google_compute_region_target_https_proxy" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['region_target_https_proxy_name'] %>" | ||
url_map = google_compute_region_url_map.default.id | ||
certificate_manager_certificates = ["//certificatemanager.googleapis.com/${google_certificate_manager_certificate.default.id}"] # [google_certificate_manager_certificate.default.id] is also acceptable | ||
} | ||
|
||
resource "google_certificate_manager_certificate" "default" { | ||
name = "<%= ctx[:vars]['certificate_manager_certificate_name'] %>" | ||
location = "us-central1" | ||
self_managed { | ||
pem_certificate = file("test-fixtures/cert.pem") | ||
pem_private_key = file("test-fixtures/private-key.pem") | ||
} | ||
} | ||
|
||
resource "google_compute_region_url_map" "default" { | ||
name = "<%= ctx[:vars]['region_url_map_name'] %>" | ||
default_service = google_compute_region_backend_service.default.id | ||
region = "us-central1" | ||
} | ||
|
||
resource "google_compute_region_backend_service" "default" { | ||
name = "<%= ctx[:vars]['region_backend_service_name'] %>" | ||
region = "us-central1" | ||
protocol = "HTTPS" | ||
timeout_sec = 30 | ||
load_balancing_scheme = "INTERNAL_MANAGED" | ||
} |