Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadRequestException: Active stages pointing to this deployment must be moved or deleted #19805

Open
mparmar19 opened this issue Jun 15, 2021 · 11 comments
Labels
bug Addresses a defect in current functionality. service/apigateway Issues and PRs that pertain to the apigateway service.

Comments

@mparmar19
Copy link

Community Note

Terraform CLI and Terraform AWS Provider Version

  • provider version - 3.45.0 (I think I tried couple more)
  • terraform version - tried in 0.13 & 0.14 all different versions.

Affected Resource(s)

  • aws_api_gateway_stage

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "aws_api_gateway_deployment" "api_deployment" {
  rest_api_id = aws_api_gateway_rest_api.api.id

  variables = {
    // Forces api deployment  everytime tf apply is run.
    build_time = timestamp()
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_api_gateway_stage" "api_stage" {
  deployment_id = aws_api_gateway_deployment.api_deployment.id
  rest_api_id   = aws_api_gateway_rest_api.api.id
  stage_name    = var.environment
  access_log_settings {
    destination_arn = aws_cloudwatch_log_group.api_gateway_access_logs.arn
    format          = "$context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] \"$context.httpMethod $context.resourcePath $context.protocol\" $context.status $context.responseLength $context.requestId"
  }
}

resource "aws_cloudwatch_log_group" "api_gateway_access_logs" {
  name = "${aws_api_gateway_rest_api.api.name}-${var.environment}-api-gateway-access-logs"
}

resource "aws_api_gateway_method_settings" "api_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.api.id
  stage_name  = aws_api_gateway_stage.api_stage.stage_name
  method_path = "*/*"

  settings {
    metrics_enabled    = true
    logging_level      = "INFO"
    data_trace_enabled = false
  }
}

resource "aws_api_gateway_base_path_mapping" "stage_mapping" {
  api_id      = aws_api_gateway_rest_api.api.id
  stage_name  = aws_api_gateway_stage.api_stage.stage_name
  domain_name = aws_api_gateway_domain_name.ldl_domain.domain_name
}

Debug Output

terraform apply

021/06/10 14:39:02 [ERROR] eval: *terraform.EvalApplyPost, err: Error creating API Gateway Stage: ConflictException: Stage already exists
2021/06/10 14:39:02 [ERROR] eval: *terraform.EvalSequence, err: Error creating API Gateway Stage: ConflictException: Stage already exists
2021/06/10 14:39:02 [ERROR] eval: *terraform.EvalApplyPost, err: error deleting API Gateway Deployment (dvff3p): BadRequestException: Active stages pointing to this deployment must be moved or deleted
2021/06/10 14:39:02 [ERROR] eval: *terraform.EvalSequence, err: error deleting API Gateway Deployment (dvff3p): BadRequestException: Active stages pointing to this deployment must be moved or deleted
aws_api_gateway_account.aws_api_gateway_cloudwatch_role_assignment: Creation complete after 0s [id=api-gateway-account]

Error: error deleting API Gateway Deployment (dvff3p): BadRequestException: Active stages pointing to this deployment must be moved or deleted



Error: Error creating API Gateway Stage: ConflictException: Stage already exists

  on main.tf line 24, in resource "aws_api_gateway_stage" "api_stage":
  24: resource "aws_api_gateway_stage" "api_stage" {

Important Factoids

References

  • #0000
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/apigateway Issues and PRs that pertain to the apigateway service. service/cloudwatchlogs labels Jun 15, 2021
@mparmar19
Copy link
Author

Feel free to ask if you are looking for more details.

@bill-rich bill-rich added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. service/cloudwatchlogs labels Jun 15, 2021
@rgleme
Copy link

rgleme commented Aug 11, 2021

I am facing same issue.

"create_before_destroy = true" solution does not work

@Type1J
Copy link

Type1J commented Mar 7, 2022

Same here. "create_before_destroy = true" isn't working.
Error: error deleting API Gateway Deployment (zxcbp2): BadRequestException: Active stages pointing to this deployment must be moved or deleted

@saiaman
Copy link

saiaman commented Nov 30, 2022

same here

@busla
Copy link

busla commented Nov 3, 2023

same

2 similar comments
@magistrser
Copy link

same

@DieterDR
Copy link

DieterDR commented Nov 9, 2023

same

@pavelpp-topia
Copy link

+1

@hansregeer
Copy link

Same here

@isaacpalomero
Copy link

same here

@demonfoo
Copy link

demonfoo commented Apr 3, 2024

I have also encountered this, after switching from using a stage_name in the aws_api_gateway_deployment block directly to use an aws_api_gateway_stage block. This is a significant problem and really needs to be addressed, as it's a major degradation of functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/apigateway Issues and PRs that pertain to the apigateway service.
Projects
None yet
Development

No branches or pull requests