Skip to content

Commit a9d9737

Browse files
committed
Update README to reflect changes to terraform version and removal of cleanup steps
1 parent e08a220 commit a9d9737

File tree

1 file changed

+27
-61
lines changed

1 file changed

+27
-61
lines changed

tests/integration/README.md

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Integrating Local Testing of AWS Deployments in MLStacks Using LocalStack
22

33
## Prerequisites
4+
45
- Docker
56
- AWS CLI
67
- Terraform
@@ -14,11 +15,13 @@
1415
Installation can be done via Homebrew, PIP, Docker CLI, or Docker Compose. For detailed instructions, refer to the [LocalStack Installation Guide](https://docs.localstack.cloud/getting-started/installation/).
1516

1617
**Homebrew**
18+
1719
```bash
1820
brew install localstack/tap/localstack-cli
1921
```
2022

2123
**PIP**
24+
2225
```bash
2326
python -m venv .venv
2427
source .venv/bin/activate
@@ -30,6 +33,7 @@ pip install localstack
3033
First, ensure Docker is running. Then, you can start LocalStack using the LocalStack CLI, Docker or Docker Compose.
3134

3235
**LocalStack CLI**
36+
3337
```bash
3438
localstack start -d
3539
```
@@ -50,11 +54,9 @@ docker-compose -f docker-compose.localstack.yml up -d
5054

5155
> You may customize this file as needed. If you don't specify any services, LocalStack defaults to running all supported AWS services. Refer to the [LocalStack Docker Compose guide](https://docs.localstack.cloud/getting-started/installation/#starting-localstack-with-docker-compose) for more details.
5256
53-
54-
5557
### Interacting with LocalStack
5658

57-
Once LocalStack is running, interact with it using `aws` commands by specifying the `endpoint-url`.
59+
Once LocalStack is running, interact with it using `aws` commands by specifying the `endpoint-url`.
5860
For instance, to create an S3 bucket:
5961

6062
```bash
@@ -64,11 +66,13 @@ aws --endpoint-url=http://localhost:4566 s3 mb mybucket
6466
To avoid having to specify the `endpoint-url` with each command, you can install the [awscli-local](https://github.com/localstack/awscli-local) package. It provides the `awslocal` command, which automatically targets the LocalStack endpoint.
6567

6668
So you can simply do this...
69+
6770
```bash
6871
awslocal s3 mb s3://test-bucket
6972
```
7073

7174
Instead of this...
75+
7276
```bash
7377
aws --endpoint-url=http://localhost:4566 s3 mb mybucket
7478
```
@@ -82,11 +86,13 @@ pip install awscli-local
8286
#### Usage examples
8387

8488
List all buckets:
89+
8590
```bash
8691
awslocal s3 ls
8792
```
8893

8994
Create a DynamoDB table:
95+
9096
```bash
9197
awslocal dynamodb create-table \
9298
--table-name test-table \
@@ -97,17 +103,16 @@ awslocal dynamodb create-table \
97103
```
98104

99105
List DynamoDB tables:
106+
100107
```bash
101108
awslocal dynamodb list-tables --region eu-north-1
102109
```
103110

104-
> **Note:**
105-
> **Most AWS services require specifying the region when using LocalStack, except for S3, which is globally accessible.**
106-
111+
> **Note:** > **Most AWS services require specifying the region when using LocalStack, except for S3, which is globally accessible.**
107112
108113
## Provisioning AWS resources with Terraform + LocalStack
109114

110-
To simulate the deployment of AWS resources locally, we utilize Terraform in conjunction with LocalStack.
115+
To simulate the deployment of AWS resources locally, we utilize Terraform in conjunction with LocalStack.
111116

112117
### Terraform Configuration
113118

@@ -136,21 +141,20 @@ force_destroy = true
136141

137142
This documentation describes the GitHub Actions workflow for LocalStack-based AWS integration testing within MLStacks. It features two primary jobs: `aws_remote_state_integration_test` and `aws_modular_integration_test`, aimed at provisioning and validating AWS resources in a local setup.
138143

139-
140144
### Implementing Terraform Overrides
141145

142146
For simulating AWS resources in our integration tests, we have two approaches:
143147

144148
1. Manual configuration using override files.
145149
2. Utilizing `tflocal` for a more automated setup.
146150

147-
#### [Manual Configuration](https://docs.localstack.cloud/user-guide/integrations/terraform/#manual-configuration)
151+
#### [Manual Configuration](https://docs.localstack.cloud/user-guide/integrations/terraform/#manual-configuration)
148152

149-
We have adopted the manual configuration method using an `_override.tf` file to specify provider settings tailored for LocalStack.
150-
This approach allows us to directly manipulate how Terraform interacts with AWS services.
153+
We have adopted the manual configuration method using an `_override.tf` file to specify provider settings tailored for LocalStack.
154+
This approach allows us to directly manipulate how Terraform interacts with AWS services.
151155

152-
> Terraform inherently recognizes any file ending in `override.tf` as an override file, allowing you to alter configurations without modifying the primary Terraform files.
153-
Detailed guidance on employing override files is available in the [Terraform Override Files Documentation](https://developer.hashicorp.com/terraform/language/files/override).
156+
> Terraform inherently recognizes any file ending in `override.tf` as an override file, allowing you to alter configurations without modifying the primary Terraform files.
157+
> Detailed guidance on employing override files is available in the [Terraform Override Files Documentation](https://developer.hashicorp.com/terraform/language/files/override).
154158
155159
#### Alternative: [Using `terraform-local`](https://docs.localstack.cloud/user-guide/integrations/terraform/)
156160

@@ -170,6 +174,7 @@ on:
170174
workflow_call:
171175
workflow_dispatch:
172176
```
177+
173178
## Jobs Overview
174179
175180
### AWS Modular Integration Test
@@ -200,12 +205,12 @@ services:
200205
```yml
201206
steps:
202207
- name: Checkout Repository
203-
uses: actions/checkout@v2
208+
uses: actions/checkout@v4.1.1
204209
205210
- name: Setup Terraform
206-
uses: hashicorp/setup-terraform@v2
211+
uses: hashicorp/setup-terraform@v3.0.0
207212
with:
208-
terraform_version: 1.3.4
213+
terraform_version: 1.6.0
209214
210215
- name: Copy Override File
211216
run: |
@@ -238,33 +243,14 @@ steps:
238243
ABSOLUTE_PATH="${GITHUB_WORKSPACE}/src/mlstacks/terraform/aws-modular/${STACK_YAML_PATH}"
239244
../../../../tests/integration/aws-modular/verify_stack.sh "$ABSOLUTE_PATH"
240245
working-directory: src/mlstacks/terraform/aws-modular
241-
242-
- name: Cleanup Resources for aws-modular
243-
run: |
244-
cd src/mlstacks/terraform/aws-modular
245-
terraform destroy -auto-approve -var-file="../../../../tests/integration/aws-modular/local.tfvars"
246-
rm -rf .terraform
247-
rm -rf volume
248-
rm -f .terraform.lock.hcl
249-
rm -f terraform.tfstate
250-
rm -f terraform.tfstate.backup
251-
rm -f localstack_providers_override.tf
252-
rm -f aws_modular_stack_*.yaml
253-
254-
- name: Ensure _override.tf Deletion
255-
if: always()
256-
run: |
257-
rm -f src/mlstacks/terraform/aws-modular/_override.tf
258-
working-directory: ${{ github.workspace }}
259246
```
247+
260248
- **Copy Override File**: Copies the `_override.tf` file into the `aws-modular` directory to ensure Terraform operations target the LocalStack environment.
261249
- **Apply Terraform Configuration**: Navigates to the `aws-modular` directory, initializes Terraform with LocalStack as the backend, validates the configuration, and applies it using a `.tfvars` file.
262250
- **Refresh Terraform State**: Refreshes the state file to ensure the latest state is accurately reflected, including the generation of the YAML file.
263251
- **Output Stack YAML Path**: Utilizes `terraform-bin` instead of the standard `terraform` command to accurately capture and output the `stack-yaml-path`. This change was required to bypass `terraform_wrapper`, and ensures Terraform commands execute directly without any abstractions.
264252
- **Run Tests to Verify Resource Provisioning**:This step captures the YAML file's path, generated by the Terraform apply process, into a variable. It then utilizes this path to run a bash script to verify the provisioning and configuration of resources.
265-
> **Note: Using an absolute path is essential here due to the test script's location in `tests/integration`.**
266-
- **Cleanup Resources**: Handles the teardown of all resources and the removal of Terraform-related files to ensure no residual state or configurations are left behind.
267-
- **Ensure `_override.tf` Deletion**: Ensures the copied `_override.tf` file is removed after job completion.
253+
> **Note: Using an absolute path is essential here due to the test script's location in `tests/integration`.**
268254

269255
### AWS Remote State Integration Test
270256

@@ -289,18 +275,17 @@ services:
289275
AWS_SECRET_ACCESS_KEY: test
290276
```
291277

292-
293278
#### Steps
294279

295280
```yml
296281
steps:
297282
- name: Checkout Repository
298-
uses: actions/checkout@v2
283+
uses: actions/checkout@v4.1.1
299284
300285
- name: Setup Terraform
301-
uses: hashicorp/setup-terraform@v2
286+
uses: hashicorp/setup-terraform@v3.0.0
302287
with:
303-
terraform_version: 1.3.4
288+
terraform_version: 1.6.0
304289
305290
- name: Copy Override File
306291
run: |
@@ -320,31 +305,12 @@ steps:
320305
AWS_ACCESS_KEY_ID: test
321306
AWS_SECRET_ACCESS_KEY: test
322307
AWS_DEFAULT_REGION: eu-north-1
323-
324-
- name: Cleanup Resources for aws-remote-state
325-
run: |
326-
cd src/mlstacks/terraform/aws-remote-state
327-
terraform destroy -auto-approve -var-file="../../../../tests/integration/aws-remote-state/local.tfvars"
328-
rm -rf .terraform
329-
rm -rf volume
330-
rm -f .terraform.lock.hcl
331-
rm -f terraform.tfstate
332-
rm -f terraform.tfstate.backup
333-
rm -f localstack_providers_override.tf
334-
335-
- name: Ensure _override.tf Deletion
336-
if: always()
337-
run: |
338-
rm -f src/mlstacks/terraform/aws-remote-state/_override.tf
339-
working-directory: ${{ github.workspace }}
340308
```
341309

342310
- **Setup Terraform**: Prepares the Terraform environment.
343311
- **Copy Override File**: Copies the `_override.tf` file into the `aws-remote-state` directory to ensure Terraform operations target the LocalStack environment.
344312
- **Apply Terraform Configuration**: Navigates to the `aws-remote-state` directory, initializes Terraform with LocalStack as the backend, validates the configuration, and applies it using a `.tfvars` file.
345313
- **Run Tests**: Executes a bash script to verify resource provisioning.
346-
- **Cleanup Resources**: Destroys provisioned resources and cleans up Terraform-related files.
347-
- **Ensure `_override.tf` Deletion**: Ensures the copied `_override.tf` file is removed after job completion.
348314

349315
## Conclusion
350316

@@ -366,4 +332,4 @@ In this documentation, we covered:
366332
- [terraform-local package](https://github.com/localstack/terraform-local)
367333
- [Override Files Terraform Documentation](https://developer.hashicorp.com/terraform/language/files/override)
368334
- [`.tfvars` documentation](https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files)
369-
- [awscli-local package](https://github.com/localstack/awscli-local)
335+
- [awscli-local package](https://github.com/localstack/awscli-local)

0 commit comments

Comments
 (0)