Skip to content

Commit 47e0872

Browse files
sean-navapbcSean Thomas
andauthored
Better handle non-us-east-1 project regions (#980)
## Ticket Resolves #947 ## Summary Enables projects to use non-us-east-1 regions by ensuring region-sensitive resources are handled correctly. ## Changes - Added `aws.us-east-1` provider alias in network layer - DNS query logging resources use us-east-1 provider (AWS requirement - Route53 query logs can only be sent to CloudWatch in us-east-1) - ACM certificates remain in the default region (must match ALB region) - Route53 zone and records use default region (global service, API works from any region) - Updated CI tests to use us-east-2 to validate multi-region support - Updated `bin/set-up-current-account` to get region from project config for consistency ## Testing - Tested on platform-test (dev network) with `manage_dns=true` and multiple apps with `enable_https=true` - Terraform plan shows no unexpected changes to existing resources - CI tests run against us-east-2 to verify non-us-east-1 region support --------- Co-authored-by: Sean Thomas <sean.thomas@navapbc.com>
1 parent d01fdca commit 47e0872

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

.github/workflows/template-only-ci-infra.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
--data base_project_name="${project_name}" \
7272
--data base_owner=platform-admins \
7373
--data base_code_repository_url=${{ github.repositoryUrl }} \
74-
--data base_default_region=us-east-1 \
74+
--data base_default_region=us-east-2 \
7575
--data app_name=app \
7676
--data app_local_port=3000 \
7777
--data app_has_dev_env_setup=true \
@@ -88,7 +88,7 @@ jobs:
8888
- name: Configure AWS credentials
8989
uses: aws-actions/configure-aws-credentials@v4
9090
with:
91-
aws-region: us-east-1
91+
aws-region: us-east-2
9292

9393
# Use access key credentials for the template infra test workflow
9494
# instead of using GitHub OIDC because only one GitHub OIDC provider

bin/set-up-current-account

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ set -euo pipefail
2525
account_name="$1"
2626

2727
account_id=$(./bin/current-account-id)
28-
region=$(./bin/current-region)
2928

30-
# Get project name
29+
# Get project name and region from project config
30+
# This ensures consistency with how terraform computes the bucket name
3131
terraform -chdir="infra/project-config" apply -auto-approve > /dev/null
3232
project_name=$(terraform -chdir="infra/project-config" output --raw project_name)
33+
region=$(terraform -chdir="infra/project-config" output --raw default_region)
3334

3435
tf_state_bucket_name="${project_name}-${account_id}-${region}-tf"
3536
tf_state_key="infra/account.tfstate"

infra/modules/domain/resources/certificates.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ locals {
2727
}
2828

2929
# ACM certificate that will be used by the load balancer.
30+
# This must be in the same region as the ALB.
3031
resource "aws_acm_certificate" "issued" {
3132
for_each = local.issued_certificate_configs
3233

infra/modules/domain/resources/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
configuration_aliases = [aws, aws.us-east-1]
6+
}
7+
}
8+
}
9+
110
# Create a Route53 hosted zone for the domain.
211
# Individual address records will be created in the service layer by the services that
312
# need them (e.g. the load balancer or CDN).

infra/modules/domain/resources/query_logs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# DNS query logging
22

33
resource "aws_cloudwatch_log_group" "dns_query_logging" {
4+
provider = aws.us-east-1
5+
46
count = var.manage_dns ? 1 : 0
57

68
name = "/dns/${var.name}"
@@ -36,6 +38,8 @@ data "aws_iam_policy_document" "dns_query_logging" {
3638
}
3739

3840
resource "aws_cloudwatch_log_resource_policy" "dns_query_logging" {
41+
provider = aws.us-east-1
42+
3943
count = var.manage_dns ? 1 : 0
4044

4145
policy_document = data.aws_iam_policy_document.dns_query_logging.json

infra/networks/main.tf.jinja

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ provider "aws" {
7272
}
7373
}
7474

75+
provider "aws" {
76+
alias = "us-east-1"
77+
region = "us-east-1"
78+
79+
default_tags {
80+
tags = local.tags
81+
}
82+
}
83+
7584
module "project_config" {
7685
source = "../project-config"
7786
}
@@ -93,7 +102,12 @@ module "network" {
93102
}
94103

95104
module "domain" {
96-
source = "../modules/domain/resources"
105+
source = "../modules/domain/resources"
106+
providers = {
107+
aws = aws
108+
aws.us-east-1 = aws.us-east-1
109+
}
110+
97111
name = local.domain_config.hosted_zone
98112
manage_dns = local.domain_config.manage_dns
99113
certificate_configs = local.domain_config.certificate_configs

template-only-test/template_infra_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
var projectName = os.Getenv("PROJECT_NAME")
1818
var imageTag = os.Getenv("IMAGE_TAG")
19+
var region = "us-east-2"
1920

2021
const maxRetries = 3
2122
const sleepBetweenRetries = 5 * time.Second
@@ -38,7 +39,6 @@ func TestEndToEnd(t *testing.T) {
3839
func ValidateAccount(t *testing.T) {
3940
projectName := projectName
4041
accountId := "533267424629"
41-
region := "us-east-1"
4242
ValidateAccountBackend(t, region, projectName)
4343
ValidateGithubActionsAuth(t, accountId, projectName)
4444
}
@@ -182,7 +182,7 @@ func ValidateDevEnvironment(t *testing.T) {
182182
serviceName := fmt.Sprintf("%s-%s", appName, environmentName)
183183
shell.RunCommand(t, shell.Command{
184184
Command: "aws",
185-
Args: []string{"ecs", "wait", "services-stable", "--cluster", serviceName, "--services", serviceName},
185+
Args: []string{"ecs", "wait", "services-stable", "--cluster", serviceName, "--services", serviceName, "--region", region},
186186
WorkingDir: "../../",
187187
})
188188

0 commit comments

Comments
 (0)