terraform-provider-google
terraform-provider-google copied to clipboard
Failed to update `target_https_proxy` from `ssl_certificates` to `certificate_map`
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
- Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
- If an issue is assigned to the
modular-magicianuser, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot, a community member has claimed the issue already.
Terraform Version
% terraform -v
Terraform v1.2.1
on darwin_amd64
+ provider registry.terraform.io/hashicorp/google v4.34.0
+ provider registry.terraform.io/hashicorp/google-beta v4.34.0
Affected Resource(s)
- google_compute_target_https_proxy
Terraform Configuration Files
This failure is happening with the change updating the ssl_certificates to the certificate_map, as below:
resource "google_compute_target_https_proxy" "https_proxy" {
name = "${var.name}-https-proxy"
description = var.https_proxy_description
url_map = google_compute_url_map.https_url_map[0].self_link
+ certificate_map = var.certificate_map
- ssl_certificates = var.ssl_certificates
ssl_policy = var.ssl_policy == "" ? module.ssl_policy[0].id : var.ssl_policy
quic_override = "NONE"
}
terraform plan output:
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# module.cloud_lb_url_map.module.https_url_map.google_compute_target_https_proxy.https_proxy[0] will be updated in-place
~ resource "google_compute_target_https_proxy" "https_proxy" {
+ certificate_map = "https://certificatemanager.googleapis.com/v1/projects/<PROJECT_NAME>/locations/global/certificateMaps/<MAP_NAME>"
id = "projects/<PROJECT_NAME>/global/targetHttpsProxies/<PROXY_NAME>"
name = "<PROXY_NAME>"
~ ssl_certificates = [
- "https://www.googleapis.com/compute/v1/projects/<PROJECT_NAME>/global/sslCertificates/<CERTIFICATE_NAME>",
]
# (8 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Expected Behavior
The target proxy should be updated without errors, and the certificate map is available.
Actual Behavior
terraform apply fails with the following error:
module.cloud_lb_url_map.module.https_url_map.google_compute_target_https_proxy.https_proxy[0]: Modifying... [id=projects/<PROJECT_NAME>/global/targetHttpsProxies/<PROXY_NAME>]
╷
│ Error: Error updating TargetHttpsProxy "projects/<PROJECT_NAME>/global/targetHttpsProxies/<PROXY_NAME>": googleapi: Error 412: Certificate Map or at least 1 SSL certificate must be specified for setting SSL certificates in TargetHttpsProxy., conditionNotMet
│
│ with module.cloud_lb_url_map.module.https_url_map.google_compute_target_https_proxy.https_proxy[0],
│ on ../../modules/cloud-load-balancing/url-map/main.tf line 90, in resource "google_compute_target_https_proxy" "https_proxy":
│ 90: resource "google_compute_target_https_proxy" "https_proxy" {
│
Steps to Reproduce
- Create
google_compute_target_https_proxywithssl_certificates. - Add
certificate_mapand removessl_certificatesat the same time. terraform apply
Research
This seems to be an API call order issue. The provider checks for changes in ssl_certificates and call API, before certificate_map.
https://github.com/hashicorp/terraform-provider-google/blob/v4.35.0/google/resource_compute_target_https_proxy.go#L366-L433
The error occurs because the Google API does not allow either the SSL certificate or the certificate map to be unbound.
Possible approaches are:
- Check for changes in
ssl_certificatesandcertificate_mapand add one before deleting one.- As far as I can see, the Google API does not return an error even if both are set at the same time.
- Allow setting both
ssl_certificatesandcertificate_mapingoogle_compute_target_https_proxyresource.- The current schema definition does not allow both to be set at the same time.
- https://github.com/hashicorp/terraform-provider-google/blob/v4.35.0/google/resource_compute_target_https_proxy.go#L69
- Being able to configure both allows users to set the certificate map first and remove the SSL certificates later.
- The current schema definition does not allow both to be set at the same time.
References
- https://github.com/hashicorp/terraform-provider-google/issues/11037
- https://github.com/hashicorp/terraform-provider-google/pull/12227
I have exactly the same issue, but as a temporary workaround until this is fixed, I used gcloud to attach the certificate map to the target proxy and used the lifecycle meta-argument to ignore changes affecting certificate_map:
lifecycle { ignore_changes = [certificate_map] } to resource "google_compute_target_https_proxy" "default"
This way I can continue to use Terraform without it wanting to destroy changes made with gcloud.
@c2thorn could you take a look at this?
The proposed approach of letting both ssl_certificates and certificate_map to be set in the google_compute_target_https_proxy resource is the correct one.
Specifying both for the duration of the migration is the only safe approach. See: https://cloud.google.com/certificate-manager/docs/migrate#apply_the_new_certificate_map_to_the_target_load_balancer
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.