Thin wrapper script to run Terraform against LocalStack
Project description
tflocal - Terraform with LocalStack
This package provides tflocal - a small wrapper script to run Terraform against LocalStack.
Prerequisites
- Python 3.x
pipterraform
How it works
The script uses the Terraform Override mechanism and creates a temporary file localstack_providers_override.tf to configure the endpoints for the AWS provider section. The endpoints for all services are configured to point to the LocalStack API (http://localhost:4566 by default).
Installation
The tflocal command line interface can be installed via pip:
pip install terraform-local
Configurations
The following environment variables can be configured:
DRY_RUN: Generate the override file without invoking TerraformTF_CMD: Terraform command to call (default:terraform)AWS_ENDPOINT_URL: hostname and port of the target LocalStack instanceLOCALSTACK_HOSTNAME: (Deprecated) host name of the target LocalStack instanceEDGE_PORT: (Deprecated) port number of the target LocalStack instanceS3_HOSTNAME: special hostname to be used to connect to LocalStack S3 (default:s3.localhost.localstack.cloud)USE_EXEC: whether to useos.execinstead ofsubprocess.Popen(try using this in case of I/O issues)<SERVICE>_ENDPOINT: setting a custom service endpoint, e.g.,COGNITO_IDP_ENDPOINT=http://example.comAWS_DEFAULT_REGION: the AWS region to use (default:us-east-1, or determined from local credentials ifboto3is installed)CUSTOMIZE_ACCESS_KEY: enables to override the static AWS Access Key ID. The following cases are taking precedence over each other from top to bottom:AWS_ACCESS_KEY_IDenvironment variable is setaccess_keyis set in the Terraform AWS providerAWS_PROFILEenvironment variable is set and configuredAWS_DEFAULT_PROFILEenvironment variable is set and configureddefaultprofile's credentials are configured- falls back to the default
AWS_ACCESS_KEY_IDmock value
AWS_ACCESS_KEY_ID: AWS Access Key ID to use for multi account setups (default:test-> account ID:000000000000)SKIP_ALIASES: Allows to skip generating AWS provider overrides for specified aliased providers, e.g.SKIP_ALIASES=aws_secrets,real_awsADDITIONAL_TF_OVERRIDE_LOCATIONS: Comma-separated list of folder paths that will also receive a temporarylocalstack_providers_override.tffile
Usage
The tflocal command has the same usage as the terraform command. For detailed usage,
please refer to the man pages of terraform --help.
Validation errors when using local terraform modules
Note that if your project uses local terraform modules, and those modules reference providers, those folders also need to receive a temporary localstack_providers_override.tf file. Without it, you would get an error that looks like this when starting to process code from inside the module
╷
│ Error: No valid credential sources found
│
│ with module.lambda.provider["registry.terraform.io/hashicorp/aws"],
│ on ../../providers.tf line 11, in provider "aws":
│ 11: provider "aws" {
│
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│
│ Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, access disabled to EC2 IMDS via client option, or "AWS_EC2_METADATA_DISABLED" environment variable
To address this issue, you may include a comma-separated list of folder paths that will recieve additional override files via an environment variable
ADDITIONAL_TF_OVERRIDE_LOCATIONS=/path/to/module1,path/to/module2 tflocal plan
See this issue for more discussion
Change Log
- v0.25.0: Improve
s3controllocal endpoint override and respectAWS_ENDPOINT_URLconfiguration formwaa - v0.24.1: Exclude broken
python-hcl2version from requirements - v0.24.0: Add support to return
terraform-localversion when callingtflocal -versionand fix AWS provider detection - v0.23.1: Fix endpoint overrides for Terraform AWS provider >= 6.0.0-beta2
- v0.23.0: Add support for
terraform_remote_statewiths3backend to read the state stored in local S3 backend; fix S3 backend config detection with multiple Terraform blocks - v0.22.0: Fix S3 backend forcing DynamoDB State Lock to be enabled by default
- v0.21.0: Add ability to drop an override file in additional locations
- v0.20.1: Fix list config rendering
- v0.20.0: Fix S3 backend option merging
- v0.19.0: Add
SKIP_ALIASESconfiguration environment variable - v0.18.2: Fix warning on aliased custom endpoint names
- v0.18.1: Fix issue with not proxied commands
- v0.18.0: Add
DRY_RUNand patch S3 backend entrypoints - v0.17.1: Add
packagingmodule to install requirements - v0.17.0: Add option to use new endpoints S3 backend options
- v0.16.1: Update Setuptools to exclude tests during packaging
- v0.16.0: Introducing semantic versioning and AWS_ENDPOINT_URL variable
- v0.15: Update endpoint overrides for Terraform AWS provider 5.22.0
- v0.14: Add support to multi-account environments
- v0.13: Fix S3 automatic
use_s3_path_styledetection when setting S3_HOSTNAME or LOCALSTACK_HOSTNAME - v0.12: Fix local endpoint overrides for Terraform AWS provider 5.9.0; fix parsing of alias and region defined as value lists
- v0.11: Minor fix to handle boolean values in S3 backend configs
- v0.10: Add support for storing state files in local S3 backends
- v0.9: Fix unsupported provider override for emrserverless
- v0.8: Configure the endpoint for opensearch service
- v0.7: Add initial support for provider aliases
- v0.6: Fix selection of default region
- v0.5: Make AWS region configurable, add
regionto provider config - v0.4: Fix using use_s3_path_style for S3_HOSTNAME=localhost; exclude
meteringmarketplaceservice endpoint - v0.3: Fix support for -chdir=... to create providers file in target directory
- v0.2: Add ability to specify custom endpoints; pass INT signals to subprocess
- v0.1: Initial release
License
This software library is released under the Apache License, Version 2.0 (see LICENSE).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file terraform_local-0.25.0.tar.gz.
File metadata
- Download URL: terraform_local-0.25.0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8730cfc92dcdbfcb10293420cafb22566d56a2af58139e8a976828b10e07c7e2
|
|
| MD5 |
7aa3982df232b2a4c9461ab10b54c4cc
|
|
| BLAKE2b-256 |
48303ca48aa0615960bc891c976512df7cca1ecf72535446f4bbe9b1ac110ebf
|
File details
Details for the file terraform_local-0.25.0-py3-none-any.whl.
File metadata
- Download URL: terraform_local-0.25.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
769044ec37a571c0c22e4e8bda1848f45baa56ff64f4cab636ea179faac61af9
|
|
| MD5 |
f4b6a98b5fc89d41d68074214062cedf
|
|
| BLAKE2b-256 |
1b2f4b7c68c43505d5a8769cbddf4dae0069b44e7f7f1c81a32d33777bdf1448
|