Search code examples
aws-lambdaaws-api-gatewayterraform

Terraform can't deploy API Gateway changes to one stage out of many?


Using this code:

resource "aws_api_gateway_deployment" "example_deployment" {
  depends_on = [
    "aws_api_gateway_method.example_api_method",
    "aws_api_gateway_integration.example_api_method_integration"
  ]
  rest_api_id = "${aws_api_gateway_rest_api.example_api.id}"
  stage_name = "${var.stage_name}"
}

I can deploy API Gateway changes to whatever stage I specify. However, this will override any existing stages. That is, if I first deploy to a stage called 'dev', then deploy to 'prod', it will erase 'dev'.

How can I achieve multi-stage deployments? So that I can first deploy to dev or staging, and if it all looks good, then deploy to the prod stage.


Solution

  • After some research, we ended up taking a different tack. Based on articles like this and this, we split our terraform into folders per stage. So if you want to deploy dev, you run terraform inside the dev folder. To avoid code duplication, you use modules. It seems to be working well, and allows us to deploy different versions of the API.