Skip to content

Commit 608f6d6

Browse files
committed
Terraform data
1 parent 52650a4 commit 608f6d6

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

infrastructure/terraform/components/api/api_gateway_base_path_mapping.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

infrastructure/terraform/components/api/api_gateway_rest_api.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)