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

While create a new api deployment aws_api_gateway_deployment tries to destroy existing deployment, which errors out as Active stages pointing to this deployment must be moved or deleted #22792

Closed
only1vinay opened this issue Sep 13, 2019 · 2 comments

Comments

@only1vinay
Copy link

only1vinay commented Sep 13, 2019

In my api gateway deployment, I usually try to create a new deployment and attach it to a new versioned stage and an existing stage.

Terraform apply errors out saying aws_api_gateway_deployment.deployment: BadRequestException: Active stages pointing to this deployment must be moved or deleted.

Terraform Version

0.12.8

Terraform Configuration Files

module "test_definition" {
  title                                      = "test-api"
  source                                     = "xxxx"
  api_version                                = "1.0.2"
}

resource "aws_api_gateway_rest_api" "test" {
  body        = module.test_definition.swagger
  description = "test"
  name        = module.test_definition.title
}

resource "null_resource" "update_rest_test" {
  depends_on = [null_resource.install_aws_cli]

  provisioner "local-exec" {
    command = "aws apigateway update-rest-api --rest-api-id ${aws_api_gateway_rest_api.test.id} --patch-operations op=replace,path=/minimumCompressionSize,value=10240"
  }

  triggers = {
    body        = sha256(module.test_definition.swagger)
    name        = module.test_definition.title
    rest_api_id = aws_api_gateway_rest_api.test.id
  }
}

resource "aws_api_gateway_deployment" "test" {
  description       = "${module.test_definition.title}-${module.test_definition.version}"
  rest_api_id       = aws_api_gateway_rest_api.test.id
  stage_description = "${module.test_definition.title}-${module.test_definition.version}"
  stage_name        = "latest"
  lifecycle {
    create_before_destroy = true
  }
}

resource "null_resource" "update_deployment_stage" {
  depends_on = [null_resource.install_aws_cli]

  provisioner "local-exec" {
    command = "aws apigateway update-stage --rest-api-id ${aws_api_gateway_rest_api.test.id} --stage-name ${aws_api_gateway_deployment.test.stage_name} --patch-operations op=replace,path=/*/*/logging/loglevel,value=INFO op=replace,path=/*/*/metrics/enabled,value=true"
  }

  triggers = {
    api_version           = module.test_definition.version
    deployment_stage_name = aws_api_gateway_deployment.test.stage_name
    rest_api_id           = aws_api_gateway_rest_api.test.id
  }
}

resource "null_resource" "create_versioned_stage" {
  depends_on = [null_resource.install_aws_cli]

  provisioner "local-exec" {
    command = "aws apigateway create-stage --rest-api-id ${aws_api_gateway_rest_api.test.id} --stage-name ${module.test_definition.version} --deployment-id ${aws_api_gateway_deployment.test.id} && aws apigateway update-stage --rest-api-id ${aws_api_gateway_rest_api.test.id} --stage-name ${module.test_definition.version} --patch-operations op=replace,path=/*/*/logging/loglevel,value=INFO op=replace,path=/*/*/metrics/enabled,value=true"
  }

  triggers = {
    api_version   = module.test_definition.version
    deployment_id = aws_api_gateway_deployment.test.id
    rest_api_id   = aws_api_gateway_rest_api.test.id
  }
}

Expected Behavior

Successfully create the deployment to the stage specified. Leave the old deployment as it is, instead of trying to delete it.

Actual Behavior

aws_api_gateway_deployment.deployment: BadRequestException: Active stages pointing to this deployment must be moved or deleted

Steps to Reproduce

Additional Context

The api gets deployed properly with new stage. But terraform errors out aws_api_gateway_deployment tries to destroy existing deployment, which errors out as Active stages pointing to this deployment must be moved or deleted.
So workaround is, I go to console, select the stage (1.0.1) and change its deployment to older version.

References

@ghost
Copy link

ghost commented Sep 13, 2019

This issue has been automatically migrated to hashicorp/terraform-provider-aws#10105 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to hashicorp/terraform-provider-aws#10105.

@ghost ghost closed this as completed Sep 13, 2019
@ghost
Copy link

ghost commented Oct 14, 2019

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Oct 14, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants