terraform-provider-aws: aws_api_gateway_deployment doesn't get updated after changes
This issue was originally opened by @blalor as hashicorp/terraform#6613. It was migrated here as part of the provider split. The original body of the issue is below.
aws_api_gateway_deployment doesn’t get updated after a dependent resource changes. For example, if I change a aws_api_gateway_integration resource to modify the request_template property, aws_api_gateway_deployment should be triggered. Since that doesn’t happen, the stage specified in the deployment continues to use the old configuration. depends_on doesn’t seem to be sufficient; I tried capturing that dependency and it didn’t work, and as I understand it, depends_on only captures ordering.
A workaround is to taint the aws_api_gateway_deployment resource after a successful apply and re-running apply.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 122
- Comments: 18 (1 by maintainers)
Links to this issue
Commits related to this issue
- resource/aws_api_gateway_deployment: Add triggers argument Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/162 Reference: https://www.terraform.io/docs/providers/null/... — committed to hashicorp/terraform-provider-aws by bflad 4 years ago
- resource/aws_api_gateway_deployment: Add triggers argument (#13054) Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/162 Reference: https://www.terraform.io/docs/provi... — committed to hashicorp/terraform-provider-aws by bflad 4 years ago
- resource/aws_api_gateway_deployment: Add triggers argument (#13054) Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/162 Reference: https://www.terraform.io/docs/provi... — committed to adamdecaf/terraform-provider-aws by bflad 4 years ago
Sharing our workaround for this issue. Initially we tried hashing the whole API definition file but then we ran into the issue that changes to variable values did not trigger a new deployment. For example, we had a lambda integration where the function name changed. The
aws_api_gateway_integrationresource got updated correctly with the new invocation ARN but a newaws_api_gateway_deploymentwas not created since the API tf file had not changed. The same would go for any parametrised value that the API uses.Currently we follow the pattern below for our APIs. Here we build a hash from the full JSON representations of all the resources that would affect the deployment, which means resource, methods, integrations, the various response types and the models. Maybe there are more types that need to go in here, but these are the ones we have found necessary.
We need to keep this list updated when we add resources and that opens up for mistakes, but this is the approach that gives us new deployments at the right time without creating them unnecessarily.
+1 😃
A workaround we use:
The effect is that when the API changes, the deployment is replaced and the stage updated. When the API doesn’t change, the deployment doesn’t change (a disadvantage of using timestamp() for the deployment variable value)
One more “astuce”: use
in the aws_api_gateway_deployment resource to avoid “Active stages” errors.
Sharing this here as well since the original was closed:
Using stage_description seems like a good work-around to solve this issue in the short term.
Hi folks 👋
Since it does not appear there will be functionality added anytime soon in Terraform core to support a form of resource configuration that will automatically triggers resource recreation when referenced resources are updated, the
aws_api_gateway_deploymentresource has been enhanced with atriggersmap argument similar to those utilized by thenull,random, andtimeproviders. This can be used by operators to automatically force a new resource (redeployment) using key/value criteria of their choosing. Its usage is fairly advanced, so caveats are added to the documentation. This functionality will release with version 2.61.0 of the Terraform AWS Provider, later next week.If this type of enhancement does not fit your needs, we would encourage you to file a new issue (potentially upstream in Terraform core since there’s not much else we can do at the provider level). Please also note that we do not intend to add this class of argument to all Terraform AWS Provider resources due to its complexity and potentially awkward configuration.
Hitting this right now as well, took me a long time to realise I had to deploy the API in the console to see all my changes 😉
@bassmanitram’s solution works just fine when using an OpenAPI Spec file.
However, I couldn’t use
base64sha256as it outputs characters that are invalid for the stage’s variable values. I used thissha1(file("./api/spec.yaml"))instead, a shorter value and only hex charsA seemingly decent suggestion from the comments on the original ticket was to add a ‘triggers’ map on the deployment resource: https://github.com/hashicorp/terraform/issues/6613#issuecomment-252275369 - this seems like maybe the least painful quick fix to the issue.