Use Terraform files in LocalStack init hooks
============================================
LocalStack Extension for using Terraform files in [init hooks](https://docs.localstack.cloud/references/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"`
* Mount a `main.tf` file 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 need `sudo` to remove the files from your host.
> If you only mount the `main.tf` file, not an entire directory, localstack will have to download the AWS terraform provider every time during `tflocal init`.
>
### Example
Example `main.tf`:
```hcl
resource "aws_s3_bucket" "example" {
bucket = "my-tf-test-bucket"
tags = {
Name = "My bucket"
Environment = "Dev"
}
}
```
Start LocalStack Pro with mounted `main.tf`:
```console
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:
```yaml
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.
```console
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
```bash
make install
```
Then, to enable the extension for LocalStack, run
```bash
localstack extensions dev enable .
```
You can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions:
```bash
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:
```bash
localstack extensions install "git+https://github.com/localstack/localstack-extensions/#egg=localstack-extension-terraform-init&subdirectory=terraform-init"
```
Raw data
{
"_id": null,
"home_page": "https://github.com/localstack/localstack-extensions/tree/main/terraform-init",
"name": "localstack-extension-terraform-init",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Thomas Rausch",
"author_email": "thomas@localstack.cloud",
"download_url": "https://files.pythonhosted.org/packages/11/75/e2d32cd3c560eaa6d2f7f0685406c44a633ca34caa71ae34f5b9b084250c/localstack_extension_terraform_init-0.2.1.tar.gz",
"platform": null,
"description": "Use Terraform files in LocalStack init hooks\n============================================\n\nLocalStack Extension for using Terraform files in [init hooks](https://docs.localstack.cloud/references/init-hooks/).\n\n> [!WARNING]\n> This extension is experimental and subject to change.\n\n> [!NOTE]\n> The extension is designed for simple self-contained terraform files, not complex projects or modules.\n> If you have larger projects, then we recommend running them from the host.\n\n## Usage\n\n* Start localstack with `EXTENSION_AUTO_INSTALL=\"localstack-extension-terraform-init\"`\n* Mount a `main.tf` file into `/etc/localstack/init/ready.d`\n\nWhen LocalStack starts up, it will install the extension, which in turn install `terraform` and `tflocal` into the container.\nIf one of the init stage directories contain a `main.tf`, the extension will run `tflocal init` and `tflocal apply` on that directory.\n\n> [!NOTE]\n> Terraform state files will be created in your host directory if you mounted an entire folder into `/etc/localstack/init/ready.d`.\n> These files are created from within the container using the container user, so you may need `sudo` to remove the files from your host.\n> If you only mount the `main.tf` file, not an entire directory, localstack will have to download the AWS terraform provider every time during `tflocal init`.\n> \n### Example\n\nExample `main.tf`:\n```hcl\nresource \"aws_s3_bucket\" \"example\" {\n bucket = \"my-tf-test-bucket\"\n\n tags = {\n Name = \"My bucket\"\n Environment = \"Dev\"\n }\n}\n```\n\nStart LocalStack Pro with mounted `main.tf`:\n\n```console\nlocalstack start \\\n -e EXTENSION_AUTO_INSTALL=\"localstack-extension-terraform-init\" \\\n -v ./main.tf:/etc/localstack/init/ready.d/main.tf\n```\n\nOr, if you use a docker-compose file:\n\n```yaml\nservices:\n localstack:\n container_name: \"localstack-main\"\n image: localstack/localstack-pro # required for Pro\n ports:\n - \"127.0.0.1:4566:4566\" # LocalStack Gateway\n environment:\n # Activate LocalStack Pro: https://docs.localstack.cloud/getting-started/auth-token/\n - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?}\n - EXTENSION_AUTO_LOAD=localstack-extension-terraform-init\"\n volumes:\n # you could also place your main.tf in `./ready.d` and set \"./ready.d:/etc/localstack/init/ready.d\"\n - \"./main.tf:/etc/localstack/init/ready.d/main.tf\"\n - \"./volume:/var/lib/localstack\"\n - \"/var/run/docker.sock:/var/run/docker.sock\"\n```\n\nIn a new terminal window, you can wait for localstack to complete and then print the created s3 buckets.\n\n```console\nlocalstack wait && awslocal s3 ls\n```\n\nThe logs should show something like:\n\n```\n2024-06-26T20:36:19.946 INFO --- [ady_monitor)] l.extension : Applying terraform project from file /etc/localstack/init/ready.d/main.tf\n2024-06-26T20:36:19.946 DEBUG --- [ady_monitor)] localstack.utils.run : Executing command: ['tflocal', '-chdir=/etc/localstack/init/ready.d', 'init', '-input=false']\n2024-06-26T20:36:26.864 DEBUG --- [ady_monitor)] localstack.utils.run : Executing command: ['tflocal', '-chdir=/etc/localstack/init/ready.d', 'apply', '-auto-approve']\n```\n\n## Install local development version\n\nTo install the extension into localstack in developer mode, you will need Python 3.10, and create a virtual environment in the extensions project.\n\nIn the newly generated project, simply run\n\n```bash\nmake install\n```\n\nThen, to enable the extension for LocalStack, run\n\n```bash\nlocalstack extensions dev enable .\n```\n\nYou can then start LocalStack with `EXTENSION_DEV_MODE=1` to load all enabled extensions:\n\n```bash\nEXTENSION_DEV_MODE=1 localstack start\n```\n\n## Install from GitHub repository\n\nTo distribute your extension, simply upload it to your github account. Your extension can then be installed via:\n\n```bash\nlocalstack extensions install \"git+https://github.com/localstack/localstack-extensions/#egg=localstack-extension-terraform-init&subdirectory=terraform-init\"\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "LocalStack Extension: LocalStack Terraform Init",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/localstack/localstack-extensions/tree/main/terraform-init"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0aacb27dea982adfc402e36566385fb51d0fb1e855e61716d99b49570dca1284",
"md5": "d2bed44c87819ba98e31a3fbe1ce4322",
"sha256": "ffbb87ab3d2ae38e57dbcb21a981b8df9f89d3039ec35da6adc7d9f934225003"
},
"downloads": -1,
"filename": "localstack_extension_terraform_init-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d2bed44c87819ba98e31a3fbe1ce4322",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4626,
"upload_time": "2024-07-16T10:05:18",
"upload_time_iso_8601": "2024-07-16T10:05:18.800572Z",
"url": "https://files.pythonhosted.org/packages/0a/ac/b27dea982adfc402e36566385fb51d0fb1e855e61716d99b49570dca1284/localstack_extension_terraform_init-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1175e2d32cd3c560eaa6d2f7f0685406c44a633ca34caa71ae34f5b9b084250c",
"md5": "3d8b3f20d7fb62bf22dd6a896adc98d3",
"sha256": "a783c2df5526cce4776869d14a58b49c124cc439cec62db8ab9fe0e8017de958"
},
"downloads": -1,
"filename": "localstack_extension_terraform_init-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "3d8b3f20d7fb62bf22dd6a896adc98d3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3949,
"upload_time": "2024-07-16T10:05:20",
"upload_time_iso_8601": "2024-07-16T10:05:20.358115Z",
"url": "https://files.pythonhosted.org/packages/11/75/e2d32cd3c560eaa6d2f7f0685406c44a633ca34caa71ae34f5b9b084250c/localstack_extension_terraform_init-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-16 10:05:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "localstack",
"github_project": "localstack-extensions",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "localstack-extension-terraform-init"
}