terraform-aws-modules / terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/apigateway-v2/aws
Apache License 2.0
148 stars 200 forks source link

Tainting aws_apiaws_apigatewayv2_stage.default with a custom domain fails to apply #83

Closed dekimsey closed 1 year ago

dekimsey commented 1 year ago

Description

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

⚠️ 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

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].

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 1 year ago

This issue was automatically closed because of stale in 10 days

dekimsey commented 1 year ago

Oh, crud, I missed the bot's ping. To my knowledge, this is still necessary.

github-actions[bot] commented 1 year ago

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.