I am trying to deploy an API in API Gateway with cloudwatch logs enabled. As given in this documentation, it's creating two stages (dev, prod). If i provide two stage names in aws_api_gateway_deployment
, aws_api_gateway_stage
which is creating two stages. If i give a same name, It's throwing an error saying Stage already exists
It looks like its not possible to create a single stage with cloudwatch logs enabled using terraform?
resource "aws_api_gateway_deployment" "test-deploy" {
depends_on = [ /*something goes here*/]
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
stage_name = "test"
variables = {
"function" = "${var.lambda_function_name}"
}
}
resource "aws_api_gateway_stage" "test" {
stage_name = "${var.stage_name}"
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
deployment_id = "${aws_api_gateway_deployment.test-deploy.id}"
}
resource "aws_api_gateway_method_settings" "settings" {
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
stage_name = "${aws_api_gateway_stage.test.stage_name}"
method_path = "*/*"
settings {
metrics_enabled = true
logging_level = "INFO"
}
}
Error:
aws_api_gateway_stage.test: Error creating API Gateway Stage: ConflictException: Stage already exists
I can't use aws_api_gateway_method_settings
without aws_api_gateway_stage
, aws_api_gateway_deployment
which creates two different stages.
It seems like a documentation problem and the example given here. aws_api_gateway_deployment
creates a stage, but i faced a issue saying stage does not exist when i don't have depends_on
statement. Its working with the following code.
resource "aws_api_gateway_deployment" "test-deploy" {
depends_on = [ /*something goes here*/]
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
stage_name = "${var.stage_name}"
variables = {
"function" = "${var.lambda_function_name}"
}
}
resource "aws_api_gateway_method_settings" "settings" {
depends_on = ["aws_api_gateway_deployment.test-deploy"]
rest_api_id = "${aws_api_gateway_rest_api.test.id}"
stage_name = "${var.stage_name}"
method_path = "*/*"
settings {
metrics_enabled = true
logging_level = "INFO"
}
}
It would be good if this documentation can be updated with a simple example without complicating/creating multiple stages.
This is still an issue IMHO. I am running into it too. Not have a stage resource works like above since the deployment resource creates it, but it should still be considered a bug since we are not able to use both the resources in the script which seems like a valid thing to do.
Can we consider opening it back up again?
Yes, this needs to be reopened.
I get ConflictException when i use "aws_api_gateway_deployment" and "aws_api_gateway_stage" because i want to set the "cache_cluster_size" on the stage.
Yea, had this issue few months ago. the trick is to depend on all related methods and integration and to just use the deployment and not the stage. The method_settings should then depend on the deployment.
This prevents assigning a client certificate to the stage that gets implicitly created by the deployment, or any other property on aws_api_gateway_stage
, unless I'm misunderstanding something.
Has anyone figured a way to make this work?
I too get a conflict when trying to enable cache on a stage.
I'm running into this bug, too. I need to explicitly configure a stage to associate it with a given certificate.
The AWS documentation says:
--stage-name (string)
The name of the Stage resource for the Deployment resource to create.
--stage-description (string)
The description of the Stage resource for the Deployment resource to create.
So apparently, AWS itself creates a new stage for each deployment. Indeed, Terraform only calls the AWS API:
deployment, err := conn.CreateDeployment(&apigateway.CreateDeploymentInput{
RestApiId: aws.String(d.Get("rest_api_id").(string)),
StageName: aws.String(d.Get("stage_name").(string)),
Description: aws.String(d.Get("description").(string)),
StageDescription: aws.String(d.Get("stage_description").(string)),
Variables: aws.StringMap(variables),
})
However, according to the AWS documentation, it seems that --stage-name
is not a required parameter. So I think the easy fix would be to make stage_name
and stage_description
optional in aws_api_gateway_deployment
.
Hello,
Any solution to this issue?
Since this issue is closed, commenting on it won't do much. There's an open issue that should be +1'd and followed instead: https://github.com/terraform-providers/terraform-provider-aws/issues/2918
For posterity, the solution is to set stage_name = ""
in the aws_api_gateway_deployment
resource.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
I'm running into this bug, too. I need to explicitly configure a stage to associate it with a given certificate.
The AWS documentation says:
So apparently, AWS itself creates a new stage for each deployment. Indeed, Terraform only calls the AWS API:
However, according to the AWS documentation, it seems that
--stage-name
is not a required parameter. So I think the easy fix would be to makestage_name
andstage_description
optional inaws_api_gateway_deployment
.