I am using Hashicorp Terraform to define an AWS API Gateway to hit a Lambda function. I have a requirement that I need to tag my AWS resources with a particular tag so that costs can be tracked. Terraform seems to allow this for most resources. However, when creating an API Gateway stage using aws_api_gateway_deployment I do not have the option to specify tags.
I see that Terraform recently added the resource aws_api_gateway_stage. This one does allow tags to be specified. But, aws_api_gateway_stage requires an aws_api_gateway_deployment. If I give them the same "stage_name" as so:
resource "aws_api_gateway_stage" "PlayLambdaApiGatewayStage" {
stage_name = "${environment}"
rest_api_id = "${aws_api_gateway_rest_api.PlayLambdaApiGateway.id}"
deployment_id = "${aws_api_gateway_deployment.PlayLambdaApiGatewayDeployment.id}"
tags = {
cost-allocation = "play-${var.environment}"
}
}
resource "aws_api_gateway_deployment" "PlayLambdaApiGatewayDeployment" {
depends_on = [
"aws_api_gateway_integration.PlayLambdaApiLambdaIntegration",
"aws_api_gateway_integration.PlayLambdaApiLambdaIntegrationRoot"
]
rest_api_id = "${aws_api_gateway_rest_api.PlayLambdaApiGateway.id}"
stage_name = "${var.environment}"
}
Then they both resources try to create the stage and I get an error:
aws_api_gateway_stage.PlayLambdaApiGatewayStage: Error creating API Gateway Stage: ConflictException: Stage already exists status code: 409, request id: f67a10c4-8aad-11e8-b486-c337ea2d214f
Here it would seem that the aws_api_gateway_deployment already created the stage, so the aws_api_gateway_stage resource failed to create it also. If I add the stage to the deployment's "depends_on" so that the stage gets created first, it complains about there being a cycle between the two.
So, it seems like:
- aws_api_gateway_stage is only intended to add additional stages to a deployment, rather than creating a stage to use for the deployment
- aws_api_gateway_deployment does not allow tags to be specified when it creates the stage.
Any ideas? What am I missing?