Skip to content

Commit 283aee8

Browse files
Tweak verbiage (#8)
* Tweak verbiage * Fix ref * Reusable workflow for matrix * Bump workflow versions * Bump workflow versions * Bump workflow versions * Drop workflow permissions, apply reusable workflow to production
1 parent 07de2b8 commit 283aee8

File tree

4 files changed

+16
-116
lines changed

4 files changed

+16
-116
lines changed

.github/workflows/deploy-sandbox.yml

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,13 @@ on:
44
pull_request:
55
branches: [ "**" ]
66

7-
permissions:
8-
id-token: write
9-
contents: read
10-
117
jobs:
128
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=(',', ':'))}")
9+
permissions:
10+
contents: read
11+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-github-matrix-tg.yml@0.1.3
12+
with:
13+
platform_environment: sandbox
6414

6515
call-terragrunt-deploy:
6616
needs: build-matrix
@@ -71,7 +21,7 @@ jobs:
7121
fail-fast: false
7222
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
7323

74-
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-terragrunt-deploy.yml@v0.1.0
24+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-terragrunt-deploy.yml@0.1.3
7525
with:
7626
tf_version: '1.5.5'
7727
tg_version: '0.54.11'

.github/workflows/release-published.yml

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,13 @@ on:
55

66
name: Deploy to Production
77

8-
permissions:
9-
contents: read
10-
11-
128
jobs:
139
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=(',', ':'))}")
10+
permissions:
11+
contents: read
12+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-github-matrix-tg.yml@0.1.3
13+
with:
14+
platform_environment: production
6515

6616
call-terragrunt-deploy:
6717
needs: build-matrix
@@ -72,12 +22,11 @@ jobs:
7222
fail-fast: false
7323
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
7424

75-
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-terragrunt-deploy.yml@v0.1.0
25+
uses: launchbynttdata/launch-workflows/.github/workflows/reusable-terragrunt-deploy.yml@0.1.3
7626
with:
7727
tf_version: '1.5.5'
7828
tg_version: '0.54.11'
7929
environment: ${{ matrix.terragrunt_environment.environment }}
8030
region: ${{ matrix.terragrunt_environment.region }}
8131
env_id: ${{ matrix.terragrunt_environment.instance }}
82-
8332
secrets: inherit

src/function/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
def lambda_handler(event, context):
77
return {
88
"statusCode": 200,
9-
"body": f"Hello from a sample Python Lambda! Payload: {PAYLOAD}",
9+
"body": f"Hello from a sample Python Lambda Function! Payload: {PAYLOAD}",
1010
}

test/unit/test_app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
def test_primary_handler():
77
result = app.lambda_handler(None, None)
88
assert result["statusCode"] == 200
9-
assert result["body"] == "Hello from a sample Python Lambda! Payload: None"
9+
assert result["body"] == "Hello from a sample Python Lambda Function! Payload: None"
1010

1111

1212
def test_primary_handler_with_payload():
1313
with patch.object(app, "PAYLOAD", "test_payload"):
1414
result = app.lambda_handler(None, None)
1515
assert result["statusCode"] == 200
1616
assert (
17-
result["body"] == "Hello from a sample Python Lambda! Payload: test_payload"
17+
result["body"]
18+
== "Hello from a sample Python Lambda Function! Payload: test_payload"
1819
)

0 commit comments

Comments
 (0)