Skip to content
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

aws_api_gateway_domain_name changing imported cert to ACM AWS Managed recreating resource instead of modify #12366

Open
ivanzolotuhin opened this issue Mar 12, 2020 · 1 comment
Labels
service/apigateway Issues and PRs that pertain to the apigateway service. waiting-response Maintainers are waiting on response from community or contributor.

Comments

@ivanzolotuhin
Copy link

ivanzolotuhin commented Mar 12, 2020

I am trying to replace imported cert which soon will expire to AWS Managed on
aws_api_gateway_domain_name Edge cert

Terraform v0.12.23

  • provider.aws v2.41.0
  • Downloading plugin for provider "aws" (hashicorp/aws) 2.52.0...

replacing

resource "aws_api_gateway_domain_name" "lambda_custom_domain" {
  domain_name             = "${var.aws_api_lambdas["friendly_domain_prefix"]}.domain.com"
  certificate_name        = "domain-custom-lambda-domain-cert"
  certificate_body        = "${file("../../../certificates/wildcard.domain.com.crt")}"
  certificate_private_key = "${file("../../../certificates/wildcard.domain.com.key")}"
  certificate_chain       = "${file("../../../certificates/wildcard.domain.com.crt.nginx.chain.pem")}"
}

to

resource "aws_api_gateway_domain_name" "lambda_custom_domain" {                                                                                                          
  domain_name             = "${var.aws_api_lambdas["friendly_domain_prefix"]}.domain.com"                                                                
  certificate_arn         = var.global["cert_arn_us"]                                                                                                                    
}            

Expected behaviour: tf just modifying resource. Only removes old cert and use Edge us-east-1 ACM cert.
What actually happens it trying to recreate resource and recreate all dependant resources which is disaster.

Workaround steps:

  1. Manually replace cert for aws api gateway domain name (choose ACM Edge cert in AWS console), "rollback cert" in AWS console for whatever reason to apply it.
  2. terraform refresh to refresh the state. On this point new certificate_arn is the right one, but plan command still offers to recreate resource, because wants to remove old certificate which not longer attached to resource.
  3. After refresh: manually change .tfstate file by removing all old certificate related fields from JSON: certificate_body, certificate_chain, certificate_name, certificate_private_key
  4. Apply/plan terraform: no changes required! which is expected after all manual manipulations.
@ghost ghost added the service/apigateway Issues and PRs that pertain to the apigateway service. label Mar 12, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 12, 2020
@justinretzolk
Copy link
Member

Hey @ivanzolotuhin 👋 Thank you for taking the time to file this. I suspect with the amount of time that's passed, you're no longer experiencing this, but I'd like to follow up just to be sure. On a quick look, it looks like certificate_body, certificate_private_key, and certificate_chain are all marked as ForceNew: true, which would at least explain why Terraform was attempting to recreate the resource.

@justinretzolk justinretzolk added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service/apigateway Issues and PRs that pertain to the apigateway service. waiting-response Maintainers are waiting on response from community or contributor.
Projects
None yet
Development

No branches or pull requests

2 participants