https://github.com/knu/tf-backend-worker
An implementation of Terraform HTTP Backend on Cloudflare Workers
https://github.com/knu/tf-backend-worker
cloudflare-workers r2 terraform terragrunt
Last synced: 6 months ago
JSON representation
An implementation of Terraform HTTP Backend on Cloudflare Workers
- Host: GitHub
- URL: https://github.com/knu/tf-backend-worker
- Owner: knu
- License: bsd-2-clause
- Created: 2024-05-06T07:20:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-24T14:50:27.000Z (12 months ago)
- Last Synced: 2024-10-25T15:21:46.645Z (12 months ago)
- Topics: cloudflare-workers, r2, terraform, terragrunt
- Language: TypeScript
- Homepage:
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terraform HTTP backend on Cloudflare Workers
This is an implementation of [Terraform HTTP backend](https://developer.hashicorp.com/terraform/language/settings/backends/http) on Cloudflare Workers.
## Configuration and Deployment
Before anything else, install packages:
```console
% npm install
```Create a KV namespace and R2 bucket for the worker, and configure `wrangler.toml` accordingly:
```console
% cp wrangler.example.toml wrangler.toml
% edit wrangler.toml
```Set the username and password for HTTP basic authentication:
```console
% wrangler secret put TF_HTTP_USERNAME --env production
% wrangler secret put TF_HTTP_PASSWORD --env production# optional: e.g. "terraform/"
% wrangler secret put BUCKET_PATH_PREFIX --env production
```Build and deploy the worker:
```console
% npm install% npm run deploy
```That's it. You'll have a worker running at `https://tf-backend-worker.your-name.workers.dev/`.
## Terraform configuration
```hcl
terraform {
backend "http" {
}
}
```Then feed the terraform command with your backend settings via environment variables like this:
```console
% TF_HTTP_ADDRESS=https://tf-backend-worker.your-name.workers.dev/terraform.tfstate \
TF_HTTP_LOCK_ADDRESS=https://tf-backend-worker.your-name.workers.dev/terraform.tfstate \
TF_HTTP_UNLOCK_ADDRESS=https://tf-backend-worker.your-name.workers.dev/terraform.tfstate \
TF_HTTP_USERNAME=username TF_HTTP_PASSWORD=password \
terraform init
```### Terragrunt
Here's an example of how to generate a backend configuration file per directory with Terragrunt:
```hcl
generate "backend" {
path = "_backend.tf"
if_exists = "overwrite_terragrunt"
contents = <