File tree Expand file tree Collapse file tree
infrastructure/terraform/components/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,3 +3,26 @@ resource "aws_api_gateway_base_path_mapping" "main" {
33 stage_name = aws_api_gateway_stage. main . stage_name
44 domain_name = aws_api_gateway_domain_name. main . domain_name
55}
6+
7+ # AWS requires base path mappings to be removed before the associated stage can
8+ # be deleted. Terraform's implicit dependency ordering is not sufficient when the
9+ # REST API is being replaced. This resource explicitly deletes the base path
10+ # mapping via the AWS CLI as a destroy-time action, before the stage is torn down.
11+ resource "terraform_data" "delete_base_path_mapping" {
12+ triggers_replace = [aws_api_gateway_base_path_mapping . main . id ]
13+
14+ provisioner "local-exec" {
15+ when = destroy
16+ command = <<- EOT
17+ aws apigateway delete-base-path-mapping \
18+ --region ${ self . input . region } \
19+ --domain-name ${ self . input . domain_name } \
20+ --base-path "(none)" 2>/dev/null || true
21+ EOT
22+ }
23+
24+ input = {
25+ region = var.region
26+ domain_name = aws_api_gateway_domain_name.main.domain_name
27+ }
28+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ resource "aws_api_gateway_rest_api" "main" {
55 disable_execute_api_endpoint = var. disable_gateway_execute_endpoint
66
77 lifecycle {
8- replace_triggered_by = [terraform_data . rest_api_security_policy ]
9- create_before_destroy = true
8+ replace_triggered_by = [terraform_data . rest_api_security_policy ]
109 }
1110}
You can’t perform that action at this time.
0 commit comments