Skip to content

Commit 4cc2502

Browse files
marwan37strickvl
andauthored
Integrate with localstack for testing AWS deployments (#145)
* Setup integration testing directories for AWS deployments * Add local.tfvars for modular and remote-state integration testing * Add verify_stack.sh scripts for AWS modular and remote state integration tests * Add __init__.py in tests/integration * Create GitHub Actions workflow for AWS integration testing * Add docker-compose.localstack.yml for LocalStack service emulation * Run format and lint scripts * Add README.md for integration tests documentation * Address typo in README * Add removal of localstack_providers_override.tf in GitHub Actions cleanup step * Revise README for enhanced Docker setup instructions and overall documentation clarity * Modified CI workflow to fix path issues, emulate tflocal, and ensure proper cleanup * Add _override.tf for LocalStack integration in tests * Improve verify_stack.sh scripts with debugging outputs * Integrate localstack-aws-integratin-test job into main CI workflow * Make aws-remote-state/verify_stack.sh executable * Add workflow dispatch trigger to workflow file * Fix path in cleanup step to correctly delete _override.tf for aws-remote-state * Update README to reflect workflow and testing approach modifications * Remove debug line displaying absolute YAML path from workflow and README * Update .github/workflows/aws-integration-test.yml Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com> * Update tests/integration/aws-modular/local.tfvars Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com> * Update tests/integration/aws-remote-state/local.tfvars Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com> * Update tests/integration/README.md Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com> * Remove cleanup steps from AWS Modular workflow Following @strickvl's suggestion, removed the terraform destroy and related cleanup commands. These steps are unnecessary for our ephemeral instances and do not impact the repo's state. Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com> * Update README to reflect changes to terraform version and removal of cleanup steps --------- Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com>
1 parent baccb96 commit 4cc2502

File tree

9 files changed

+577
-0
lines changed

9 files changed

+577
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
permissions:
2+
contents: read
3+
name: LocalStack AWS Integration Test
4+
on:
5+
workflow_call:
6+
workflow_dispatch:
7+
jobs:
8+
aws_modular_integration_test:
9+
name: aws_modular_integration_test
10+
runs-on: ubuntu-latest
11+
services:
12+
setup-localstack-service:
13+
image: localstack/localstack
14+
ports:
15+
- '4566:4566'
16+
env:
17+
SERVICES: 's3,iam,sts'
18+
DEFAULT_REGION: eu-north-1
19+
FORCE_NONINTERACTIVE: 1
20+
AWS_ACCESS_KEY_ID: test
21+
AWS_SECRET_ACCESS_KEY: test
22+
steps:
23+
- name: Checkout Repository
24+
uses: actions/checkout@v4.1.1
25+
26+
- name: Setup Terraform
27+
uses: hashicorp/setup-terraform@v3.0.0
28+
with:
29+
terraform_version: 1.6.0
30+
31+
- name: Copy Override File
32+
run: |
33+
cp tests/integration/_override.tf src/mlstacks/terraform/aws-modular/_override.tf
34+
35+
- name: Apply Terraform Configuration
36+
run: |
37+
export TF_CLI_ARGS_apply="-compact-warnings"
38+
terraform init -backend-config="path=./terraform.tfstate"
39+
terraform validate
40+
terraform apply -auto-approve -var-file="../../../../tests/integration/aws-modular/local.tfvars"
41+
working-directory: src/mlstacks/terraform/aws-modular
42+
43+
- name: Refresh Terraform State
44+
run: terraform refresh
45+
working-directory: src/mlstacks/terraform/aws-modular
46+
47+
- name: Output Stack YAML Path
48+
id: set_output
49+
run: |
50+
OUTPUT=$(terraform-bin output -raw stack-yaml-path)
51+
echo "stack_yaml_path=$OUTPUT" >> $GITHUB_OUTPUT
52+
working-directory: src/mlstacks/terraform/aws-modular
53+
env:
54+
terraform_wrapper: false
55+
56+
- name: Run Tests to Verify Resource Provisioning
57+
run: |
58+
STACK_YAML_PATH="${{ steps.set_output.outputs.stack_yaml_path }}"
59+
ABSOLUTE_PATH="${GITHUB_WORKSPACE}/src/mlstacks/terraform/aws-modular/${STACK_YAML_PATH}"
60+
../../../../tests/integration/aws-modular/verify_stack.sh "$ABSOLUTE_PATH"
61+
working-directory: src/mlstacks/terraform/aws-modular
62+
63+
aws_remote_state_integration_test:
64+
name: aws_remote_state_integration_test
65+
runs-on: ubuntu-latest
66+
services:
67+
setup-localstack-service:
68+
image: localstack/localstack
69+
ports:
70+
- '4566:4566'
71+
env:
72+
SERVICES: 's3,dynamodb,iam,sts'
73+
DEFAULT_REGION: eu-north-1
74+
FORCE_NONINTERACTIVE: 1
75+
AWS_ACCESS_KEY_ID: test
76+
AWS_SECRET_ACCESS_KEY: test
77+
steps:
78+
- name: Checkout Repository
79+
uses: actions/checkout@v4.1.1
80+
81+
- name: Setup Terraform
82+
uses: hashicorp/setup-terraform@v3.0.0
83+
with:
84+
terraform_version: 1.6.0
85+
86+
- name: Copy Override File
87+
run: |
88+
cp tests/integration/_override.tf src/mlstacks/terraform/aws-remote-state/_override.tf
89+
90+
- name: Apply Terraform Configuration for aws-remote-state
91+
run: |
92+
export TF_CLI_ARGS_apply="-compact-warnings"
93+
cd src/mlstacks/terraform/aws-remote-state
94+
terraform init -backend-config="path=./terraform.tfstate"
95+
terraform validate
96+
terraform apply -auto-approve -var-file="../../../../tests/integration/aws-remote-state/local.tfvars"
97+
98+
- name: Run Tests to Verify Resource Provisioning
99+
run: ./tests/integration/aws-remote-state/verify_stack.sh
100+
env:
101+
AWS_ACCESS_KEY_ID: test
102+
AWS_SECRET_ACCESS_KEY: test
103+
AWS_DEFAULT_REGION: eu-north-1

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ jobs:
111111
files: "."
112112
config: ./.typos.toml
113113

114+
localstack-aws-integration-test:
115+
uses: ./.github/workflows/aws-integration-test.yml
116+
secrets: inherit
117+
114118
aws_test:
115119
name: aws_test
116120
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)