You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/integration/README.md
+27-61Lines changed: 27 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Integrating Local Testing of AWS Deployments in MLStacks Using LocalStack
2
2
3
3
## Prerequisites
4
+
4
5
- Docker
5
6
- AWS CLI
6
7
- Terraform
@@ -14,11 +15,13 @@
14
15
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/).
15
16
16
17
**Homebrew**
18
+
17
19
```bash
18
20
brew install localstack/tap/localstack-cli
19
21
```
20
22
21
23
**PIP**
24
+
22
25
```bash
23
26
python -m venv .venv
24
27
source .venv/bin/activate
@@ -30,6 +33,7 @@ pip install localstack
30
33
First, ensure Docker is running. Then, you can start LocalStack using the LocalStack CLI, Docker or Docker Compose.
31
34
32
35
**LocalStack CLI**
36
+
33
37
```bash
34
38
localstack start -d
35
39
```
@@ -50,11 +54,9 @@ docker-compose -f docker-compose.localstack.yml up -d
50
54
51
55
> 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.
52
56
53
-
54
-
55
57
### Interacting with LocalStack
56
58
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`.
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.
> **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.**
107
112
108
113
## Provisioning AWS resources with Terraform + LocalStack
109
114
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.
111
116
112
117
### Terraform Configuration
113
118
@@ -136,21 +141,20 @@ force_destroy = true
136
141
137
142
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.
138
143
139
-
140
144
### Implementing Terraform Overrides
141
145
142
146
For simulating AWS resources in our integration tests, we have two approaches:
143
147
144
148
1. Manual configuration using override files.
145
149
2. Utilizing `tflocal` for a more automated setup.
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.
151
155
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).
- **Copy Override File**: Copies the `_override.tf` file into the `aws-modular` directory to ensure Terraform operations target the LocalStack environment.
261
249
- **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.
262
250
- **Refresh Terraform State**: Refreshes the state file to ensure the latest state is accurately reflected, including the generation of the YAML file.
263
251
- **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.
264
252
- **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`.**
- **Setup Terraform**: Prepares the Terraform environment.
343
311
- **Copy Override File**: Copies the `_override.tf` file into the `aws-remote-state` directory to ensure Terraform operations target the LocalStack environment.
344
312
- **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.
345
313
- **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.
348
314
349
315
## Conclusion
350
316
@@ -366,4 +332,4 @@ In this documentation, we covered:
0 commit comments