From 4cc25023d61241c6e1cee16692e41bd111041677 Mon Sep 17 00:00:00 2001 From: Marwan Zaarab <99911676+marwan37@users.noreply.github.com> Date: Mon, 19 Feb 2024 08:16:08 -0600 Subject: [PATCH] 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 * Update tests/integration/aws-modular/local.tfvars Co-authored-by: Alex Strick van Linschoten * Update tests/integration/aws-remote-state/local.tfvars Co-authored-by: Alex Strick van Linschoten * Update tests/integration/README.md Co-authored-by: Alex Strick van Linschoten * 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 * Update README to reflect changes to terraform version and removal of cleanup steps --------- Co-authored-by: Alex Strick van Linschoten --- .github/workflows/aws-integration-test.yml | 103 ++++++ .github/workflows/ci.yml | 4 + tests/integration/README.md | 335 ++++++++++++++++++ tests/integration/_override.tf | 35 ++ tests/integration/aws-modular/local.tfvars | 15 + tests/integration/aws-modular/verify_stack.sh | 23 ++ .../integration/aws-remote-state/local.tfvars | 16 + .../aws-remote-state/verify_stack.sh | 30 ++ .../integration/docker-compose.localstack.yml | 16 + 9 files changed, 577 insertions(+) create mode 100644 .github/workflows/aws-integration-test.yml create mode 100644 tests/integration/README.md create mode 100644 tests/integration/_override.tf create mode 100644 tests/integration/aws-modular/local.tfvars create mode 100755 tests/integration/aws-modular/verify_stack.sh create mode 100644 tests/integration/aws-remote-state/local.tfvars create mode 100755 tests/integration/aws-remote-state/verify_stack.sh create mode 100644 tests/integration/docker-compose.localstack.yml diff --git a/.github/workflows/aws-integration-test.yml b/.github/workflows/aws-integration-test.yml new file mode 100644 index 00000000..39fa910e --- /dev/null +++ b/.github/workflows/aws-integration-test.yml @@ -0,0 +1,103 @@ +permissions: + contents: read +name: LocalStack AWS Integration Test +on: + workflow_call: + workflow_dispatch: +jobs: + aws_modular_integration_test: + name: aws_modular_integration_test + runs-on: ubuntu-latest + services: + setup-localstack-service: + image: localstack/localstack + ports: + - '4566:4566' + env: + SERVICES: 's3,iam,sts' + DEFAULT_REGION: eu-north-1 + FORCE_NONINTERACTIVE: 1 + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test + steps: + - name: Checkout Repository + uses: actions/checkout@v4.1.1 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3.0.0 + with: + terraform_version: 1.6.0 + + - name: Copy Override File + run: | + cp tests/integration/_override.tf src/mlstacks/terraform/aws-modular/_override.tf + + - name: Apply Terraform Configuration + run: | + export TF_CLI_ARGS_apply="-compact-warnings" + terraform init -backend-config="path=./terraform.tfstate" + terraform validate + terraform apply -auto-approve -var-file="../../../../tests/integration/aws-modular/local.tfvars" + working-directory: src/mlstacks/terraform/aws-modular + + - name: Refresh Terraform State + run: terraform refresh + working-directory: src/mlstacks/terraform/aws-modular + + - name: Output Stack YAML Path + id: set_output + run: | + OUTPUT=$(terraform-bin output -raw stack-yaml-path) + echo "stack_yaml_path=$OUTPUT" >> $GITHUB_OUTPUT + working-directory: src/mlstacks/terraform/aws-modular + env: + terraform_wrapper: false + + - name: Run Tests to Verify Resource Provisioning + run: | + STACK_YAML_PATH="${{ steps.set_output.outputs.stack_yaml_path }}" + ABSOLUTE_PATH="${GITHUB_WORKSPACE}/src/mlstacks/terraform/aws-modular/${STACK_YAML_PATH}" + ../../../../tests/integration/aws-modular/verify_stack.sh "$ABSOLUTE_PATH" + working-directory: src/mlstacks/terraform/aws-modular + + aws_remote_state_integration_test: + name: aws_remote_state_integration_test + runs-on: ubuntu-latest + services: + setup-localstack-service: + image: localstack/localstack + ports: + - '4566:4566' + env: + SERVICES: 's3,dynamodb,iam,sts' + DEFAULT_REGION: eu-north-1 + FORCE_NONINTERACTIVE: 1 + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test + steps: + - name: Checkout Repository + uses: actions/checkout@v4.1.1 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3.0.0 + with: + terraform_version: 1.6.0 + + - name: Copy Override File + run: | + cp tests/integration/_override.tf src/mlstacks/terraform/aws-remote-state/_override.tf + + - name: Apply Terraform Configuration for aws-remote-state + run: | + export TF_CLI_ARGS_apply="-compact-warnings" + cd src/mlstacks/terraform/aws-remote-state + terraform init -backend-config="path=./terraform.tfstate" + terraform validate + terraform apply -auto-approve -var-file="../../../../tests/integration/aws-remote-state/local.tfvars" + + - name: Run Tests to Verify Resource Provisioning + run: ./tests/integration/aws-remote-state/verify_stack.sh + env: + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test + AWS_DEFAULT_REGION: eu-north-1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7590d4e7..4b9e05dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,6 +111,10 @@ jobs: files: "." config: ./.typos.toml + localstack-aws-integration-test: + uses: ./.github/workflows/aws-integration-test.yml + secrets: inherit + aws_test: name: aws_test runs-on: ubuntu-latest diff --git a/tests/integration/README.md b/tests/integration/README.md new file mode 100644 index 00000000..500c56ea --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,335 @@ +# Integrating Local Testing of AWS Deployments in MLStacks Using LocalStack + +## Prerequisites + +- Docker +- AWS CLI +- Terraform + +## LocalStack + +[LocalStack](https://www.localstack.cloud/) is a powerful tool that simulates AWS cloud services on your local machine, providing a development environment that closely mirrors the live AWS environment without incurring the costs associated with real AWS services. It supports a wide range of AWS services, allowing you to test various deployment configurations before pushing them to AWS. For more information and a complete guide on how to use LocalStack, visit the [LocalStack Documentation](https://docs.localstack.cloud/getting-started/). + +### Installation + +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/). + +**Homebrew** + +```bash +brew install localstack/tap/localstack-cli +``` + +**PIP** + +```bash +python -m venv .venv +source .venv/bin/activate +pip install localstack +``` + +### Starting LocalStack + +First, ensure Docker is running. Then, you can start LocalStack using the LocalStack CLI, Docker or Docker Compose. + +**LocalStack CLI** + +```bash +localstack start -d +``` + +**Docker CLI** + +```bash +docker run --rm -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack +``` + +**Docker Compose** + +Use the `docker-compose.localstack.yml` file in `test/integration` for an easy setup. From that directory, run: + +```bash +docker-compose -f docker-compose.localstack.yml up -d +``` + +> 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. + +### Interacting with LocalStack + +Once LocalStack is running, interact with it using `aws` commands by specifying the `endpoint-url`. +For instance, to create an S3 bucket: + +```bash +aws --endpoint-url=http://localhost:4566 s3 mb mybucket +``` + +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. + +So you can simply do this... + +```bash +awslocal s3 mb s3://test-bucket +``` + +Instead of this... + +```bash +aws --endpoint-url=http://localhost:4566 s3 mb mybucket +``` + +#### Installation + +```bash +pip install awscli-local +``` + +#### Usage examples + +List all buckets: + +```bash +awslocal s3 ls +``` + +Create a DynamoDB table: + +```bash +awslocal dynamodb create-table \ + --table-name test-table \ + --key-schema AttributeName=id,KeyType=HASH \ + --attribute-definitions AttributeName=id,AttributeType=S \ + --billing-mode PAY_PER_REQUEST \ + --region eu-north-1 +``` + +List DynamoDB tables: + +```bash +awslocal dynamodb list-tables --region eu-north-1 +``` + +> **Note:** > **Most AWS services require specifying the region when using LocalStack, except for S3, which is globally accessible.** + +## Provisioning AWS resources with Terraform + LocalStack + +To simulate the deployment of AWS resources locally, we utilize Terraform in conjunction with LocalStack. + +### Terraform Configuration + +Instead of relying solely on traditional Terraform files, we incorporate `.tfvars` files to specify resource configurations. These files are used in conjunction with generic Terraform configuration files located in the project's Terraform directories (`aws-modular` and `aws-remote-state`). + +`.tfvars` files enable external variable definitions for Terraform, allowing for dynamic adjustments to resource specifications and testing parameters without modifying the primary Terraform configuration. Refer to the [`.tfvars` documentation](https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files) for more details. + +**Example .`tfvars` file for `aws-modular`:** + +```hcl +region = "eu-north-1" +bucket_name = "local-artifact-store-1" +enable_orchestrator_skypilot = true +``` + +**Example `.tfvars` for `aws-remote-state`**: + +```hcl +region = "eu-north-1" +bucket_name = "local-artifact-store-2" +dynamo_table_name = "remote-terraform-state-locks" +force_destroy = true +``` + +## GitHub Actions Workflow for AWS Integration Testing + +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. + +### Implementing Terraform Overrides + +For simulating AWS resources in our integration tests, we have two approaches: + +1. Manual configuration using override files. +2. Utilizing `tflocal` for a more automated setup. + +#### [Manual Configuration](https://docs.localstack.cloud/user-guide/integrations/terraform/#manual-configuration) + +We have adopted the manual configuration method using an `_override.tf` file to specify provider settings tailored for LocalStack. +This approach allows us to directly manipulate how Terraform interacts with AWS services. + +> Terraform inherently recognizes any file ending in `override.tf` as an override file, allowing you to alter configurations without modifying the primary Terraform files. +> Detailed guidance on employing override files is available in the [Terraform Override Files Documentation](https://developer.hashicorp.com/terraform/language/files/override). + +#### Alternative: [Using `terraform-local`](https://docs.localstack.cloud/user-guide/integrations/terraform/) + +For an automated setup, you can install the [`terraform-local`](https://github.com/localstack/terraform-local) package, which provides the `tflocal` command. It acts as a wrapper around Terraform commands, automatically adjusting them for compatibility with LocalStack. This eliminates the need for manual endpoint configuration, but requires additional setup for `tflocal`. + +## Workflow Setup + +### Trigger Events + +The workflow is designed to be triggered on two events: + +- `workflow_call`: Allows this workflow to be called from other workflows within the repository. +- `workflow_dispatch`: Enables manual triggering of the workflow from the GitHub Actions UI. + +```yml +on: + workflow_call: + workflow_dispatch: +``` + +## Jobs Overview + +### AWS Modular Integration Test + +This job tests the provisioning of AWS resources, including the optional SkyPilot orchestrator, within the `aws-modular` configuration. + +#### Setup LocalStack Service + +- Uses a service container to spin up LocalStack, mapping port 4566 for AWS service emulation. +- Configures AWS services (`s3`, `iam`, `sts`) and sets the default region to `eu-north-1`. + +```yml +services: + setup-localstack-service: + image: localstack/localstack + ports: + - '4566:4566' + env: + SERVICES: 's3,iam,sts' + DEFAULT_REGION: eu-north-1 + FORCE_NONINTERACTIVE: 1 + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test +``` + +#### Steps + +```yml +steps: + - name: Checkout Repository + uses: actions/checkout@v4.1.1 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3.0.0 + with: + terraform_version: 1.6.0 + + - name: Copy Override File + run: | + cp tests/integration/_override.tf src/mlstacks/terraform/aws-modular/_override.tf + + - name: Apply Terraform Configuration + run: | + export TF_CLI_ARGS_apply="-compact-warnings" + terraform init -backend-config="path=./terraform.tfstate" + terraform validate + terraform apply -auto-approve -var-file="../../../../tests/integration/aws-modular/local.tfvars" + working-directory: src/mlstacks/terraform/aws-modular + + - name: Refresh Terraform State + run: terraform refresh + working-directory: src/mlstacks/terraform/aws-modular + + - name: Output Stack YAML Path + id: set_output + run: | + OUTPUT=$(terraform-bin output -raw stack-yaml-path) + echo "stack_yaml_path=$OUTPUT" >> $GITHUB_OUTPUT + working-directory: src/mlstacks/terraform/aws-modular + env: + terraform_wrapper: false + + - name: Run Tests to Verify Resource Provisioning + run: | + STACK_YAML_PATH="${{ steps.set_output.outputs.stack_yaml_path }}" + ABSOLUTE_PATH="${GITHUB_WORKSPACE}/src/mlstacks/terraform/aws-modular/${STACK_YAML_PATH}" + ../../../../tests/integration/aws-modular/verify_stack.sh "$ABSOLUTE_PATH" + working-directory: src/mlstacks/terraform/aws-modular +``` + +- **Copy Override File**: Copies the `_override.tf` file into the `aws-modular` directory to ensure Terraform operations target the LocalStack environment. +- **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. +- **Refresh Terraform State**: Refreshes the state file to ensure the latest state is accurately reflected, including the generation of the YAML file. +- **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. +- **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. + > **Note: Using an absolute path is essential here due to the test script's location in `tests/integration`.** + +### AWS Remote State Integration Test + +This job focuses on testing the provisioning of AWS resources related to remote state management, such as S3 buckets for artifact storage and DynamoDB tables for state locking. + +#### Setup LocalStack Service + +- Uses a service container to spin up LocalStack, mapping port 4566 for AWS service emulation. +- Configures essential AWS services (`s3`, `dynamodb`, `iam`, `sts`) and sets the default region to `eu-north-1`. + +```yml +services: + setup-localstack-service: + image: localstack/localstack + ports: + - '4566:4566' + env: + SERVICES: 's3,dynamodb,iam,sts' + DEFAULT_REGION: eu-north-1 + FORCE_NONINTERACTIVE: 1 + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test +``` + +#### Steps + +```yml +steps: + - name: Checkout Repository + uses: actions/checkout@v4.1.1 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3.0.0 + with: + terraform_version: 1.6.0 + + - name: Copy Override File + run: | + cp tests/integration/_override.tf src/mlstacks/terraform/aws-remote-state/_override.tf + + - name: Apply Terraform Configuration for aws-remote-state + run: | + export TF_CLI_ARGS_apply="-compact-warnings" + cd src/mlstacks/terraform/aws-remote-state + terraform init -backend-config="path=./terraform.tfstate" + terraform validate + terraform apply -auto-approve -var-file="../../../../tests/integration/aws-remote-state/local.tfvars" + + - name: Run Tests to Verify Resource Provisioning + run: ./tests/integration/aws-remote-state/verify_stack.sh + env: + AWS_ACCESS_KEY_ID: test + AWS_SECRET_ACCESS_KEY: test + AWS_DEFAULT_REGION: eu-north-1 +``` + +- **Setup Terraform**: Prepares the Terraform environment. +- **Copy Override File**: Copies the `_override.tf` file into the `aws-remote-state` directory to ensure Terraform operations target the LocalStack environment. +- **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. +- **Run Tests**: Executes a bash script to verify resource provisioning. + +## Conclusion + +In this documentation, we covered: + +- Setting up LocalStack for local emulation of AWS services. +- Installing and starting LocalStack using various methods. +- Using `awslocal` for simplified AWS service interaction. +- Integrating Terraform with LocalStack using override files and `.tfvars` files for resource provisioning. +- Integrating Terraform with LocalStack using `tflocal` and `.tfvars` files as an alternative. +- Configuring GitHub Actions for AWS integration testing with LocalStack. + +## Links + +- [LocalStack Documentation](https://docs.localstack.cloud/getting-started/) +- [LocalStack Installation Guide](https://docs.localstack.cloud/getting-started/installation/) +- [LocalStack GitHub Actions Integration Guide](https://docs.localstack.cloud/user-guide/ci/github-actions/) +- [LocalStack terraform-local (`tflocal`) integration](https://docs.localstack.cloud/user-guide/integrations/terraform/) +- [terraform-local package](https://github.com/localstack/terraform-local) +- [Override Files Terraform Documentation](https://developer.hashicorp.com/terraform/language/files/override) +- [`.tfvars` documentation](https://developer.hashicorp.com/terraform/language/values/variables#variable-definitions-tfvars-files) +- [awscli-local package](https://github.com/localstack/awscli-local) diff --git a/tests/integration/_override.tf b/tests/integration/_override.tf new file mode 100644 index 00000000..ca2105fd --- /dev/null +++ b/tests/integration/_override.tf @@ -0,0 +1,35 @@ +provider "aws" { + access_key = "test" + secret_key = "test" + region = "eu-north-1" + s3_use_path_style = true + skip_credentials_validation = true + skip_metadata_api_check = true + skip_requesting_account_id = true + + endpoints { + apigateway = "http://localhost:4566" + apigatewayv2 = "http://localhost:4566" + cloudformation = "http://localhost:4566" + cloudwatch = "http://localhost:4566" + dynamodb = "http://localhost:4566" + ec2 = "http://localhost:4566" + es = "http://localhost:4566" + elasticache = "http://localhost:4566" + firehose = "http://localhost:4566" + iam = "http://localhost:4566" + kinesis = "http://localhost:4566" + lambda = "http://localhost:4566" + rds = "http://localhost:4566" + redshift = "http://localhost:4566" + route53 = "http://localhost:4566" + s3 = "http://localhost:4566" + secretsmanager = "http://localhost:4566" + ses = "http://localhost:4566" + sns = "http://localhost:4566" + sqs = "http://localhost:4566" + ssm = "http://localhost:4566" + stepfunctions = "http://localhost:4566" + sts = "http://localhost:4566" + } +} diff --git a/tests/integration/aws-modular/local.tfvars b/tests/integration/aws-modular/local.tfvars new file mode 100644 index 00000000..3a5688eb --- /dev/null +++ b/tests/integration/aws-modular/local.tfvars @@ -0,0 +1,15 @@ +# Copyright (c) ZenML GmbH 2024. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing +# permissions and limitations under the License. +region = "eu-north-1" +bucket_name = "local-aws-modular-artifact-store" +enable_orchestrator_skypilot = true \ No newline at end of file diff --git a/tests/integration/aws-modular/verify_stack.sh b/tests/integration/aws-modular/verify_stack.sh new file mode 100755 index 00000000..b6e94716 --- /dev/null +++ b/tests/integration/aws-modular/verify_stack.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +STACK_YAML_PATH=$1 + +# Debugging +echo "Verifying YAML at: $STACK_YAML_PATH" +echo "Contents of the YAML file:" +cat "$STACK_YAML_PATH" + +# Verifying artifact_store and orchestrator configurations in the YAML file +if grep -q "artifact_store:" "$STACK_YAML_PATH" && grep -q "flavor: local" "$STACK_YAML_PATH"; then + echo "Artifact store configuration verification in YAML file succeeded." +else + echo "Artifact store configuration verification in YAML file failed." + exit 1 +fi + +if grep -q "orchestrator:" "$STACK_YAML_PATH" && grep -q "flavor: vm_aws" "$STACK_YAML_PATH" && grep -q "name: aws_skypilot_orchestrator" "$STACK_YAML_PATH"; then + echo "Skypilot orchestrator configuration verification succeeded." +else + echo "Skypilot orchestrator configuration verification failed." + exit 1 +fi diff --git a/tests/integration/aws-remote-state/local.tfvars b/tests/integration/aws-remote-state/local.tfvars new file mode 100644 index 00000000..f41a18e2 --- /dev/null +++ b/tests/integration/aws-remote-state/local.tfvars @@ -0,0 +1,16 @@ +# Copyright (c) ZenML GmbH 2024. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing +# permissions and limitations under the License. +region = "eu-north-1" +bucket_name = "local-aws-remote-artifact-store" +dynamo_table_name = "local-aws-remote-terraform-state-locks" +force_destroy = true diff --git a/tests/integration/aws-remote-state/verify_stack.sh b/tests/integration/aws-remote-state/verify_stack.sh new file mode 100755 index 00000000..915a6dc6 --- /dev/null +++ b/tests/integration/aws-remote-state/verify_stack.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +ENDPOINT_URL="http://localhost:4566" +AWS_REGION="eu-north-1" + +# Debugging +echo "Listing S3 buckets:" +aws s3 ls --endpoint-url="$ENDPOINT_URL" +echo "Listing DynamoDB tables:" +aws dynamodb list-tables --endpoint-url="$ENDPOINT_URL" --region "$AWS_REGION" + +# Verifying S3 bucket creation +BUCKET_NAME="local-aws-remote-artifact-store" +BUCKET_LIST=$(aws s3 ls --endpoint-url="$ENDPOINT_URL") +if echo "$BUCKET_LIST" | grep -q "$BUCKET_NAME"; then + echo "S3 bucket '$BUCKET_NAME' creation verification succeeded." +else + echo "S3 bucket '$BUCKET_NAME' creation verification failed." + exit 1 +fi + +# Verifying DynamoDB table creation +TABLE_NAME="local-aws-remote-terraform-state-locks" +TABLE_LIST=$(aws dynamodb list-tables --endpoint-url="$ENDPOINT_URL" --region "$AWS_REGION") +if echo "$TABLE_LIST" | grep -q "$TABLE_NAME"; then + echo "DynamoDB table '$TABLE_NAME' creation verification succeeded." +else + echo "DynamoDB table '$TABLE_NAME' creation verification failed." + exit 1 +fi diff --git a/tests/integration/docker-compose.localstack.yml b/tests/integration/docker-compose.localstack.yml new file mode 100644 index 00000000..6e97d7f2 --- /dev/null +++ b/tests/integration/docker-compose.localstack.yml @@ -0,0 +1,16 @@ +version: "3.8" + +services: + localstack: + container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}" + image: localstack/localstack + ports: + - "127.0.0.1:4566:4566" # LocalStack Gateway + - "127.0.0.1:4510-4559:4510-4559" # external services port range + environment: + - DEBUG=${DEBUG:-0} + - SERVICES=s3,dynamodb,iam,sts + + volumes: + - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" + - "/var/run/docker.sock:/var/run/docker.sock"