I’m a terraform beginner, trying to deploy an api gateway with integration to a vpc link.
When I terraform apply
on my project, neither the aws_apigatewayv2_stage
resource nor the aws_apigatewayv2_deployment
resource that I have defined in my files actually result in the corresponding stage and deployment showing up on AWS.
Here are the resource blocks I’ve written to define those resources
# api gateway stage
resource "aws_apigatewayv2_stage" "this" {
api_id = aws_apigatewayv2_api.this.id
name = "$default" # public url for deployments to this stage will not have any version or stage qualifier (as you might see like 'api.example.com/v2/route')
auto_deploy = true
default_route_settings {
detailed_metrics_enabled = true
}
deployment_id = aws_apigatewayv2_deployment.this.id
access_log_settings {
destination_arn = aws_cloudwatch_log_group.api_gateway_access_lg.arn
format = jsonencode({
"requestId" = "$context.requestId"
"ip" = "$context.identity.sourceIp"
"requestTime" = "$context.requestTime"
"httpMethod" = "$context.httpMethod"
"routeKey" = "$context.routeKey"
"status" = "$context.status"
"responseLength" = "$context.responseLength"
})
}
}
# deployment
resource "aws_apigatewayv2_deployment" "this" {
api_id = aws_apigatewayv2_api.this.id
triggers = {
redeployment = sha1(join(",", tolist([
jsonencode(aws_apigatewayv2_integration.this),
jsonencode(aws_apigatewayv2_route.api_makedataset_post_route),
])))
}
lifecycle {
create_before_destroy = true
}
}
I’m omitting all the other resources to try to isolate the parts of my config (e.g. aws_apigatewayv2_api
) that might be failing.
I suspect that this failure may have to do with the aws_cloudwatch_log_group
resource on which my stage depends:
# api log group
resource "aws_cloudwatch_log_group" "api_gateway_access_lg" {
name = "apgtwy/blw-data-api-server"
skip_destroy = true
retention_in_days = 30
}
When I run terraform apply
on my project, I get the following error message:
Error: creating CloudWatch Logs Log Group (apgtwy/blw-data-api-server): operation error CloudWatch Logs: CreateLogGroup, https response error StatusCode: 400, RequestID: e6a3d0bb-b39a-453a-a5a3-1411cea5a986, ResourceAlreadyExistsException: The specified log group already exists
Of course, I do not want terraform to overwrite that log group if it exists, because I don’t want the old logs destroyed. (hence I set skip_destroy = true
in the log_group resource. So I’m interpreting this error message (probably incorrectly) as a signal that things are working as I intend.
But of course, they’re not working as I intend, because my stage
and deployment
do not get built.
Is it possible that skip_destroy=true
or something else about the log group resource is blocking the deployment of my stage
and deployment
resources? There are no other error messages showing up when I do terraform apply
.