|
| 1 | +# Custom domain resources for the prod MCP server. |
| 2 | +# Only created when var.custom_domain is non-empty (i.e. boston-prod workspace). |
| 3 | +# DNS records are managed externally by city IT — no Route53 resources here. |
| 4 | + |
| 5 | +locals { |
| 6 | + create_custom_domain = var.custom_domain != "" ? 1 : 0 |
| 7 | +} |
| 8 | + |
| 9 | +# ── ACM Certificate ────────────────────────────────────────────────────────── |
| 10 | + |
| 11 | +resource "aws_acm_certificate" "mcp_cert" { |
| 12 | + count = local.create_custom_domain |
| 13 | + domain_name = var.custom_domain |
| 14 | + validation_method = "DNS" |
| 15 | + |
| 16 | + tags = { |
| 17 | + Name = "${local.lambda_name}-cert" |
| 18 | + Environment = var.stage_name |
| 19 | + } |
| 20 | + |
| 21 | + lifecycle { |
| 22 | + create_before_destroy = true |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +# ── API Gateway Custom Domain Name ────────────────────────────────────────── |
| 27 | + |
| 28 | +resource "aws_api_gateway_domain_name" "custom" { |
| 29 | + count = local.create_custom_domain |
| 30 | + domain_name = var.custom_domain |
| 31 | + |
| 32 | + regional_certificate_arn = aws_acm_certificate.mcp_cert[0].arn |
| 33 | + |
| 34 | + endpoint_configuration { |
| 35 | + types = ["REGIONAL"] |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +# ── Base Path Mapping ─────────────────────────────────────────────────────── |
| 40 | +# Empty base path so data-mcp.boston.gov/mcp hits the existing /mcp resource. |
| 41 | + |
| 42 | +resource "aws_api_gateway_base_path_mapping" "custom" { |
| 43 | + count = local.create_custom_domain |
| 44 | + domain_name = aws_api_gateway_domain_name.custom[0].domain_name |
| 45 | + api_id = aws_api_gateway_rest_api.mcp_api.id |
| 46 | + stage_name = aws_api_gateway_stage.prod.stage_name |
| 47 | +} |
0 commit comments