Skip to content

Commit

Permalink
Merge pull request #414 from jdno/terragrunt-regions
Browse files Browse the repository at this point in the history
Support multiple AWS regions in Terragrunt
  • Loading branch information
jdno authored May 7, 2024
2 parents b9d73b1 + d7674a1 commit 54bd88a
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 18 deletions.
6 changes: 5 additions & 1 deletion terragrunt/accounts/bors-prod/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": "bors-prod",
"region": "us-east-2"
"regions": [
{
"region": "us-east-2"
}
]
}
}
6 changes: 5 additions & 1 deletion terragrunt/accounts/bors-staging/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": "bors-staging",
"region": "us-east-2"
"regions": [
{
"region": "us-east-2"
}
]
}
}
6 changes: 5 additions & 1 deletion terragrunt/accounts/crates-io-prod/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": "crates-io-prod",
"region": "us-west-1"
"regions": [
{
"region": "us-west-1"
}
]
}
}
10 changes: 9 additions & 1 deletion terragrunt/accounts/crates-io-staging/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"aws": {
"profile": "crates-io-staging",
"region": "us-west-1"
"regions": [
{
"region": "us-west-1"
},
{
"region": "us-east-1",
"alias": "us-east-1"
}
]
}
}
6 changes: 5 additions & 1 deletion terragrunt/accounts/dev-desktops-prod/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": "dev-desktops-prod",
"region": "us-east-1"
"regions": [
{
"region": "us-east-1"
}
]
}
}
6 changes: 5 additions & 1 deletion terragrunt/accounts/legacy/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": null,
"region": "us-west-1"
"regions": [
{
"region": "us-west-1"
}
]
}
}
6 changes: 5 additions & 1 deletion terragrunt/accounts/root/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": "rust-root",
"region": "us-east-1"
"regions": [
{
"region": "us-east-1"
}
]
}
}
6 changes: 5 additions & 1 deletion terragrunt/accounts/sync-team-prod/account.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"aws": {
"profile": "sync-team-prod",
"region": "us-east-2"
"regions": [
{
"region": "us-east-2"
}
]
}
}
25 changes: 15 additions & 10 deletions terragrunt/terragrunt-locals.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,25 @@ def calculate_remote_state_key(account_json_file, terragrunt_dir):


def calculate_providers_content(account_json):
if account_json["aws"]["profile"] is not None:
return f"""
provider "aws" {{
profile = "{account_json["aws"]["profile"]}"
region = "{account_json["aws"]["region"]}"
}}
"""
else:
return f"""
providers = ""

for region in account_json["aws"]["regions"]:
body = f' region = "{region["region"]}"'

if account_json["aws"]["profile"] is not None:
body += f'\n profile = "{account_json["aws"]["profile"]}"'

if "alias" in region:
body += f'\n alias = "{region["alias"]}"'

providers += f"""
provider "aws" {{
region = "{account_json["aws"]["region"]}"
{body}
}}
"""

return providers


def profile_args(account_json):
if account_json["aws"]["profile"] is not None:
Expand Down

0 comments on commit 54bd88a

Please sign in to comment.