terraform-aws-apigateway-v2 icon indicating copy to clipboard operation
terraform-aws-apigateway-v2 copied to clipboard

Tainting aws_apiaws_apigatewayv2_stage.default with a custom domain fails to apply

Open dekimsey opened this issue 3 years ago β€’ 0 comments

Description

Tainting the aws_apigatewayv2_stage.default resource with a configured custom domain fails to apply cleanly.

  • [x] βœ‹ I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Module version [Required]: 2.2.0

  • Terraform version:

Terraform v1.3.1
on darwin_arm64
  • Provider version(s):
+ provider registry.terraform.io/hashicorp/aws v4.33.0
+ provider registry.terraform.io/hashicorp/null v3.1.1
+ provider registry.terraform.io/hashicorp/tls v4.0.3

Reproduction Code [Required]

Steps to reproduce the behavior:

Workspace? Yes Cleared local cache? Yes

Create API Gateway with a custom domain and automatic mapping, make sure the default stage is enabled.

  1. terraform apply
  2. terarform taint aws_apigatewayv2_stage.default
  3. terraform apply

Expected behavior

The default stage is successfully unattached to the custom domain and deleted.

Actual behavior

$ terraform apply
...
module.demo.aws_apigatewayv2_stage.default[0]: Destroying... [id=$default]

β”‚ Error: deleting API Gateway v2 stage ($default): BadRequestException: Deleting stage $default failed. Please remove all base path mappings related to the stage in your domains: demo.example.com

Terminal Output Screenshot(s)

Terraform will perform the following actions:

  # module.demo.aws_apigatewayv2_api_mapping.this[0] will be updated in-place
  ~ resource "aws_apigatewayv2_api_mapping" "this" {
        id          = "coffee"
      ~ stage       = "$default" -> (known after apply)
        # (2 unchanged attributes hidden)
    }

  # module.demo.aws_apigatewayv2_stage.default[0] is tainted, so must be replaced
-/+ resource "aws_apigatewayv2_stage" "default" {
      ~ arn             = "arn:aws:apigateway:us-east-2::/apis/deadbeef/stages/$default" -> (known after apply)
      ~ deployment_id   = "xfnne7" -> (known after apply)
      ~ execution_arn   = "arn:aws:execute-api:us-east-2:1337133713370:deadbeef/$default" -> (known after apply)
      ~ id              = "$default" -> (known after apply)
      ~ invoke_url      = "https://deadbeef.execute-api.us-east-2.amazonaws.com/" -> (known after apply)
        name            = "$default"
      - stage_variables = {} -> null
        ...
    }

Plan: 1 to add, 1 to change, 1 to destroy.

Do you want to perform these actions in workspace "stg"?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.demo.aws_apigatewayv2_stage.default[0]: Destroying... [id=$default]
β•·
β”‚ Error: deleting API Gateway v2 stage ($default): BadRequestException: Deleting stage $default failed. Please remove all base path mappings related to the stage in your domains: demo.example.com
β”‚
β”‚
β•΅

Additional context

I believe the aws_apigatewayv2_api_mapping.this resource needs a replace_triggered_by set for aws_apigatewayv2_stage.default[0].

dekimsey avatar Oct 06 '22 20:10 dekimsey