Skip to content

Commit 07de2b8

Browse files
Move TG workflow to separate workflow repo (#7)
1 parent 83edee8 commit 07de2b8

File tree

4 files changed

+149
-245
lines changed

4 files changed

+149
-245
lines changed

.github/workflows/deploy-sandbox.yml

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,81 @@
11
name: Deploy Sandbox Environment
22

33
on:
4-
pull_request:
5-
branches: [ "**" ]
4+
pull_request:
5+
branches: [ "**" ]
66

77
permissions:
8-
id-token: write
9-
contents: read
8+
id-token: write
9+
contents: read
1010

1111
jobs:
12-
build-matrix:
13-
runs-on: ubuntu-latest
14-
outputs:
15-
matrix: ${{ steps.build-matrix.outputs.matrix }}
16-
steps:
17-
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
18-
- name: Build Environment Matrix
19-
id: build-matrix
20-
shell: python
21-
env:
22-
PLATFORM_ENVIRONMENT: "sandbox"
23-
run: |
24-
from pathlib import Path
25-
import os
26-
import json
27-
28-
def discover_environments(platform_path: Path = Path("platform")) -> list[Path]:
29-
return [d for d in platform_path.iterdir() if d.is_dir()]
30-
31-
def discover_regions(environment_path: Path) -> list[Path]:
32-
return [d for d in environment_path.iterdir() if d.is_dir()]
33-
34-
def discover_instances(region_path: Path) -> list[Path]:
35-
return [d for d in region_path.iterdir() if d.is_dir()]
36-
37-
try:
38-
ENVIRONMENT = os.environ['PLATFORM_ENVIRONMENT']
39-
except KeyError as ke:
40-
raise ValueError("Environment variable named PLATFORM_ENVIRONMENT was not found. This variable must be supplied so that a matrix of environments can be built!")
41-
42-
if len(ENVIRONMENT) == 0:
43-
raise ValueError("Environment variable PLATFORM_ENVIRONMENT was empty. This variable must be supplied so that a matrix of environments can be built!")
44-
45-
all_environments = discover_environments()
46-
matrix = {"terragrunt_environment": []}
47-
try:
48-
selected_environment = list(filter(lambda x: x.name == ENVIRONMENT, all_environments))[0]
49-
except Exception:
50-
raise ValueError(f"Expected environment '{ENVIRONMENT}' not found in {all_environments}")
51-
52-
regions = discover_regions(environment_path=selected_environment)
53-
54-
for region_path in regions:
55-
region_instances = discover_instances(region_path=region_path)
56-
for instance in region_instances:
57-
matrix["terragrunt_environment"].append({"environment": selected_environment.name, "region": region_path.name, "instance": instance.name})
58-
59-
print("Generated the following environment matrix:")
60-
print(json.dumps(matrix, indent=4))
61-
62-
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
63-
f.write(f"matrix={json.dumps(matrix, separators=(',', ':'))}")
64-
65-
call-terragrunt-deploy:
66-
needs: build-matrix
67-
permissions:
68-
contents: read
69-
id-token: write
70-
strategy:
71-
fail-fast: false
72-
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
73-
74-
uses: ./.github/workflows/terragrunt-deploy.yml
75-
with:
76-
tf_version: '1.5.5'
77-
tg_version: '0.54.11'
78-
environment: ${{ matrix.terragrunt_environment.environment }}
79-
region: ${{ matrix.terragrunt_environment.region }}
80-
env_id: ${{ matrix.terragrunt_environment.instance }}
81-
82-
secrets: inherit
12+
build-matrix:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
matrix: ${{ steps.build-matrix.outputs.matrix }}
16+
steps:
17+
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
18+
- name: Build Environment Matrix
19+
id: build-matrix
20+
shell: python
21+
env:
22+
PLATFORM_ENVIRONMENT: "sandbox"
23+
run: |
24+
from pathlib import Path
25+
import os
26+
import json
27+
28+
def discover_environments(platform_path: Path = Path("platform")) -> list[Path]:
29+
return [d for d in platform_path.iterdir() if d.is_dir()]
30+
31+
def discover_regions(environment_path: Path) -> list[Path]:
32+
return [d for d in environment_path.iterdir() if d.is_dir()]
33+
34+
def discover_instances(region_path: Path) -> list[Path]:
35+
return [d for d in region_path.iterdir() if d.is_dir()]
36+
37+
try:
38+
ENVIRONMENT = os.environ['PLATFORM_ENVIRONMENT']
39+
except KeyError as ke:
40+
raise ValueError("Environment variable named PLATFORM_ENVIRONMENT was not found. This variable must be supplied so that a matrix of environments can be built!")
41+
42+
if len(ENVIRONMENT) == 0:
43+
raise ValueError("Environment variable PLATFORM_ENVIRONMENT was empty. This variable must be supplied so that a matrix of environments can be built!")
44+
45+
all_environments = discover_environments()
46+
matrix = {"terragrunt_environment": []}
47+
try:
48+
selected_environment = list(filter(lambda x: x.name == ENVIRONMENT, all_environments))[0]
49+
except Exception:
50+
raise ValueError(f"Expected environment '{ENVIRONMENT}' not found in {all_environments}")
51+
52+
regions = discover_regions(environment_path=selected_environment)
53+
54+
for region_path in regions:
55+
region_instances = discover_instances(region_path=region_path)
56+
for instance in region_instances:
57+
matrix["terragrunt_environment"].append({"environment": selected_environment.name, "region": region_path.name, "instance": instance.name})
58+
59+
print("Generated the following environment matrix:")
60+
print(json.dumps(matrix, indent=4))
61+
62+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
63+
f.write(f"matrix={json.dumps(matrix, separators=(',', ':'))}")
64+
65+
call-terragrunt-deploy:
66+
needs: build-matrix
67+
permissions:
68+
contents: read
69+
id-token: write
70+
strategy:
71+
fail-fast: false
72+
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
73+
74+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-terragrunt-deploy.yml@v0.1.0
75+
with:
76+
tf_version: '1.5.5'
77+
tg_version: '0.54.11'
78+
environment: ${{ matrix.terragrunt_environment.environment }}
79+
region: ${{ matrix.terragrunt_environment.region }}
80+
env_id: ${{ matrix.terragrunt_environment.instance }}
81+
secrets: inherit

.github/workflows/draft-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
- uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5
1919
with:
2020
commitish: main
21-
disable-autolabeler: true
2221
latest: true
2322
env:
2423
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
11
on:
2-
release:
3-
types:
4-
- published
2+
release:
3+
types:
4+
- published
55

66
name: Deploy to Production
77

88
permissions:
9-
contents: read
9+
contents: read
1010

1111

1212
jobs:
13-
build-matrix:
14-
runs-on: ubuntu-latest
15-
outputs:
16-
matrix: ${{ steps.build-matrix.outputs.matrix }}
17-
steps:
18-
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
19-
- name: Build Environment Matrix
20-
id: build-matrix
21-
shell: python
22-
env:
23-
PLATFORM_ENVIRONMENT: "production"
24-
run: |
25-
from pathlib import Path
26-
import os
27-
import json
28-
29-
def discover_environments(platform_path: Path = Path("platform")) -> list[Path]:
30-
return [d for d in platform_path.iterdir() if d.is_dir()]
31-
32-
def discover_regions(environment_path: Path) -> list[Path]:
33-
return [d for d in environment_path.iterdir() if d.is_dir()]
34-
35-
def discover_instances(region_path: Path) -> list[Path]:
36-
return [d for d in region_path.iterdir() if d.is_dir()]
37-
38-
try:
39-
ENVIRONMENT = os.environ['PLATFORM_ENVIRONMENT']
40-
except KeyError as ke:
41-
raise ValueError("Environment variable named PLATFORM_ENVIRONMENT was not found. This variable must be supplied so that a matrix of environments can be built!")
42-
43-
if len(ENVIRONMENT) == 0:
44-
raise ValueError("Environment variable PLATFORM_ENVIRONMENT was empty. This variable must be supplied so that a matrix of environments can be built!")
45-
46-
all_environments = discover_environments()
47-
matrix = {"terragrunt_environment": []}
48-
try:
49-
selected_environment = list(filter(lambda x: x.name == ENVIRONMENT, all_environments))[0]
50-
except Exception:
51-
raise ValueError(f"Expected environment '{ENVIRONMENT}' not found in {all_environments}")
52-
53-
regions = discover_regions(environment_path=selected_environment)
54-
55-
for region_path in regions:
56-
region_instances = discover_instances(region_path=region_path)
57-
for instance in region_instances:
58-
matrix["terragrunt_environment"].append({"environment": selected_environment.name, "region": region_path.name, "instance": instance.name})
59-
60-
print("Generated the following environment matrix:")
61-
print(json.dumps(matrix, indent=4))
62-
63-
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
64-
f.write(f"matrix={json.dumps(matrix, separators=(',', ':'))}")
65-
66-
call-terragrunt-deploy:
67-
needs: build-matrix
68-
permissions:
69-
contents: read
70-
id-token: write
71-
strategy:
72-
fail-fast: false
73-
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
74-
75-
uses: ./.github/workflows/terragrunt-deploy.yml
76-
with:
77-
tf_version: '1.5.5'
78-
tg_version: '0.54.11'
79-
environment: ${{ matrix.terragrunt_environment.environment }}
80-
region: ${{ matrix.terragrunt_environment.region }}
81-
env_id: ${{ matrix.terragrunt_environment.instance }}
82-
83-
secrets: inherit
13+
build-matrix:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
matrix: ${{ steps.build-matrix.outputs.matrix }}
17+
steps:
18+
- uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f
19+
- name: Build Environment Matrix
20+
id: build-matrix
21+
shell: python
22+
env:
23+
PLATFORM_ENVIRONMENT: "production"
24+
run: |
25+
from pathlib import Path
26+
import os
27+
import json
28+
29+
def discover_environments(platform_path: Path = Path("platform")) -> list[Path]:
30+
return [d for d in platform_path.iterdir() if d.is_dir()]
31+
32+
def discover_regions(environment_path: Path) -> list[Path]:
33+
return [d for d in environment_path.iterdir() if d.is_dir()]
34+
35+
def discover_instances(region_path: Path) -> list[Path]:
36+
return [d for d in region_path.iterdir() if d.is_dir()]
37+
38+
try:
39+
ENVIRONMENT = os.environ['PLATFORM_ENVIRONMENT']
40+
except KeyError as ke:
41+
raise ValueError("Environment variable named PLATFORM_ENVIRONMENT was not found. This variable must be supplied so that a matrix of environments can be built!")
42+
43+
if len(ENVIRONMENT) == 0:
44+
raise ValueError("Environment variable PLATFORM_ENVIRONMENT was empty. This variable must be supplied so that a matrix of environments can be built!")
45+
46+
all_environments = discover_environments()
47+
matrix = {"terragrunt_environment": []}
48+
try:
49+
selected_environment = list(filter(lambda x: x.name == ENVIRONMENT, all_environments))[0]
50+
except Exception:
51+
raise ValueError(f"Expected environment '{ENVIRONMENT}' not found in {all_environments}")
52+
53+
regions = discover_regions(environment_path=selected_environment)
54+
55+
for region_path in regions:
56+
region_instances = discover_instances(region_path=region_path)
57+
for instance in region_instances:
58+
matrix["terragrunt_environment"].append({"environment": selected_environment.name, "region": region_path.name, "instance": instance.name})
59+
60+
print("Generated the following environment matrix:")
61+
print(json.dumps(matrix, indent=4))
62+
63+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
64+
f.write(f"matrix={json.dumps(matrix, separators=(',', ':'))}")
65+
66+
call-terragrunt-deploy:
67+
needs: build-matrix
68+
permissions:
69+
contents: read
70+
id-token: write
71+
strategy:
72+
fail-fast: false
73+
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
74+
75+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-terragrunt-deploy.yml@v0.1.0
76+
with:
77+
tf_version: '1.5.5'
78+
tg_version: '0.54.11'
79+
environment: ${{ matrix.terragrunt_environment.environment }}
80+
region: ${{ matrix.terragrunt_environment.region }}
81+
env_id: ${{ matrix.terragrunt_environment.instance }}
82+
83+
secrets: inherit

0 commit comments

Comments
 (0)