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

Trigger API gateway deployments as per the docs #66

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions terraform/modules/api_route/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
output "resource_id" {
value = aws_api_gateway_resource.resource.id
}

output "all_ids" {
value = [
aws_api_gateway_resource.resource.id,
aws_api_gateway_method.method.id,
aws_api_gateway_integration.integration.id
]
}
26 changes: 20 additions & 6 deletions terraform/modules/stack/api_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@ resource "aws_api_gateway_rest_api" "catalogue" {
}
}

// This is quite tricky, context for the way it's configured can be found here:
// https:/hashicorp/terraform-provider-aws/issues/11344#issuecomment-765138213
// If you're seeing issues with changes not appearing (or even disappearing), then
// manually deploying resources via the AWS Console can often help.
resource "aws_api_gateway_deployment" "default" {
rest_api_id = aws_api_gateway_rest_api.catalogue.id

triggers = {
// This sometimes causes a deploy to occur before resources have been updated
// This is mentioned in the docs but it's unclear to me how to resolve it;
// since we don't expect the gateway config to change often it's been left as-is
// with the proviso that sometimes a manual deploy from the console is necessary
// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/apigatewayv2_deployment#redeployment-triggers
redeployment = join("", [filesha1("${path.module}/api_gateway.tf"), filesha1("${path.module}/static_responses.tf")])
// IMPORTANT: New resources need to be added here manually (see above)
redeployment = sha1(jsonencode(concat(
[
aws_api_gateway_resource.v2.id,
aws_api_gateway_gateway_response.no_resource.id,
aws_api_gateway_gateway_response.not_found_404.id,
],
module.works_route.all_ids,
module.images_route.all_ids,
module.single_image_route.all_ids,
module.single_work_route.all_ids,
module.items_route.all_ids,
module.default_route.all_ids,
module.v1_root_gone.all_ids,
module.v1_gone.all_ids
)))
}

lifecycle {
Expand Down
10 changes: 10 additions & 0 deletions terraform/modules/static_response/output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
output "resource_id" {
value = aws_api_gateway_resource.static.id
}

output "all_ids" {
value = [
aws_api_gateway_resource.static.id,
aws_api_gateway_method.static.id,
aws_api_gateway_integration.static.id,
aws_api_gateway_method_response.static.id,
aws_api_gateway_integration_response.static.id
]
}