Use Terraform files in LocalStack init hooks
LocalStack Extension for using Terraform files in init hooks.
[!WARNING] This extension is experimental and subject to change.
[!NOTE] The extension is designed for simple self-contained terraform files, not complex projects or modules. If you have larger projects, then we recommend running them from the host.
Usage
- Start localstack with
EXTENSION_AUTO_INSTALL="localstack-extension-terraform-init" - Optionally specify
TERRAFORM_VERSION=1.13.2(currently defaults to 1.5.7) - Mount a
main.tffile into/etc/localstack/init/ready.d
When LocalStack starts up, it will install the extension, which in turn install terraform and tflocal into the container.
If one of the init stage directories contain a main.tf, the extension will run tflocal init and tflocal apply on that directory.
[!NOTE] Terraform state files will be created in your host directory if you mounted an entire folder into
/etc/localstack/init/ready.d. These files are created from within the container using the container user, so you may needsudoto remove the files from your host. If you only mount themain.tffile, not an entire directory, localstack will have to download the AWS terraform provider every time duringtflocal init.
Example
Example main.tf:
resource "aws_s3_bucket" "example" {
bucket = "my-tf-test-bucket"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
Start LocalStack Pro with mounted main.tf:
localstack start \
-e EXTENSION_AUTO_INSTALL="localstack-extension-terraform-init" \
-v ./main.tf:/etc/localstack/init/ready.d/main.tf
Or, if you use a docker-compose file:
services:
localstack:
container_name: "localstack-main"
image: localstack/localstack-pro # required for Pro
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
environment:
# Activate LocalStack Pro: https://docs.localstack.cloud/getting-started/auth-token/
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?}
- EXTENSION_AUTO_LOAD=localstack-extension-terraform-init"
volumes:
# you could also place your main.tf in `./ready.d` and set "./ready.d:/etc/localstack/init/ready.d"
- "./main.tf:/etc/localstack/init/ready.d/main.tf"
- "./volume:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
In a new terminal window, you can wait for localstack to complete and then print the created s3 buckets.
localstack wait && awslocal s3 ls
The logs should show something like:
2024-06-26T20:36:19.946 INFO --- [ady_monitor)] l.extension : Applying terraform project from file /etc/localstack/init/ready.d/main.tf
2024-06-26T20:36:19.946 DEBUG --- [ady_monitor)] localstack.utils.run : Executing command: ['tflocal', '-chdir=/etc/localstack/init/ready.d', 'init', '-input=false']
2024-06-26T20:36:26.864 DEBUG --- [ady_monitor)] localstack.utils.run : Executing command: ['tflocal', '-chdir=/etc/localstack/init/ready.d', 'apply', '-auto-approve']
Install local development version
To install the extension into localstack in developer mode, you will need Python 3.10, and create a virtual environment in the extensions project.
In the newly generated project, simply run
make install
Then, to enable the extension for LocalStack, run
localstack extensions dev enable .
You can then start LocalStack with EXTENSION_DEV_MODE=1 to load all enabled extensions:
EXTENSION_DEV_MODE=1 localstack start
Install from GitHub repository
To distribute your extension, simply upload it to your github account. Your extension can then be installed via:
localstack extensions install "git+https://github.com/localstack/localstack-extensions/#egg=localstack-extension-terraform-init&subdirectory=terraform-init"
Metadata
Release files for localstack-extension-terraform-init 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| localstack_extension_terraform_init-0.3.1.tar.gz | 4.5 kB | Without provenance | Details for localstack_extension_terraform_init-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| localstack_extension_terraform_init-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for localstack_extension_terraform_init-0.3.1-py3-none-any.whl |
Total release size: 10.0 kB
Release files / localstack_extension_terraform_init-0.3.1.tar.gz
| Download URL | localstack_extension_terraform_init-0.3.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72d498213a77652f1933161c6ec35439e01a4d6808965ddea51847511ef581b3
|
|
BLAKE2b-256 checksum How to use checksums |
2ac24d1cd8bd42e0242a9d6b263bfa672d11235e3977d1204784cff0a1cf701d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / localstack_extension_terraform_init-0.3.1-py3-none-any.whl
| Download URL | localstack_extension_terraform_init-0.3.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47778843df9ce5c8522ae8a7ed056ba077564f2f540dede48b48729adfd513dd
|
|
BLAKE2b-256 checksum How to use checksums |
db2e87cf6ccc0014f0ca75dab681e34985a8f88d2612533621e8e5cb4023af1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for localstack-extension-terraform-init 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.