Skip to content

Commit

Permalink
Introduce intermediary stage to allow proper resource recreation
Browse files Browse the repository at this point in the history
Unfortunately the current setup still has the issue that prevents us from replacing the API-GW resources when the Swagger file changes.

Fortunately someone else has chimed in with their solution, and this seemed to work during my tests:
hashicorp/terraform#6613 (comment)

Also changed the output of the module to reflect custom domains.

(My test case was only about changing the description variable of the API Gateway module, which affects the Swagger file.)
  • Loading branch information
szilveszter committed Nov 8, 2017
1 parent f3574d8 commit bdb642e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions modules/apigateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ resource "aws_api_gateway_rest_api" "api" {
description = "${var.description} (stage: ${var.stage})"
}

resource "aws_api_gateway_deployment" "stage" {
depends_on = ["aws_api_gateway_rest_api.api"]

resource "aws_api_gateway_deployment" "deployment" {
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
stage_name = "${var.stage}"
stage_name = "${var.stage}_deploy"

variables = {
"version" = "${md5(data.template_file.swagger_file.rendered)}"
}
}

resource "aws_api_gateway_stage" "stage" {
stage_name = "${var.stage}"
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
deployment_id = "${aws_api_gateway_deployment.deployment.id}"
}

data "aws_acm_certificate" "ssl_cert" {
Expand All @@ -99,7 +102,7 @@ resource "aws_api_gateway_base_path_mapping" "basepath" {
count = "${var.enable_custom_domain}"

api_id = "${aws_api_gateway_rest_api.api.id}"
stage_name = "${aws_api_gateway_deployment.stage.stage_name}"
stage_name = "${aws_api_gateway_stage.stage.stage_name}"
domain_name = "${aws_api_gateway_domain_name.domain.domain_name}"
base_path = "${var.base_path}"
}
Expand Down
5 changes: 4 additions & 1 deletion modules/apigateway/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ output "api_id" {
value = "${aws_api_gateway_rest_api.api.id}"
}
output "invoke_url" {
value = "${aws_api_gateway_deployment.stage.invoke_url}"
# If we have a custom domain set up, we should point the endpoint to that.
# Otherwise take the deployment's invoke URL, and strip the intermediary
# stage suffix from the URL.
value = "${var.enable_custom_domain ? format("https://%s", var.custom_domain) : replace(aws_api_gateway_deployment.deployment.invoke_url, "_deploy", "")}"
}

0 comments on commit bdb642e

Please sign in to comment.