terraform
This module provides functionality to run Terraform operations inside acontainerized Dagger pipeline. It supports applying, destroying, and
initializing Terraform configurations with optional variable injection.
The module executes Terraform in a controlled container environment,
optionally injecting HCL-style variables and secret JSON variables. It
is especially useful in CI/CD scenarios where reproducibility and
secure secret handling are required.
Supported features include:
- Running `terraform init`, `apply`, or `destroy` inside a Dagger container
- Supplying key-value `-var` arguments via a comma-separated string
- Injecting a `terraform.tfvars.json` file via a mounted Dagger secret
- Fetching outputs from the Terraform state in JSON format
This module is intended to encapsulate Terraform workflows inside a
container runtime, simplifying automation across cloud or local environments.
Installation
dagger install github.com/stuttgart-things/dagger/terraform@v0.133.0Entrypoint
Return Type
Terraform Example
dagger -m github.com/stuttgart-things/dagger/terraform@7228d65097efda4d607fbd7e335567b608d04f65 call \
func (m *MyModule) Example() *dagger.Terraform {
return dag.
Terraform()
}@function
def example() -> dagger.Terraform:
return (
dag.terraform()
)@func()
example(): Terraform {
return dag
.terraform()
}Types
Terraform 🔗
baseImage() 🔗
Return Type
String ! Example
dagger -m github.com/stuttgart-things/dagger/terraform@7228d65097efda4d607fbd7e335567b608d04f65 call \
base-imagefunc (m *MyModule) Example(ctx context.Context) string {
return dag.
Terraform().
Baseimage(ctx)
}@function
async def example() -> str:
return await (
dag.terraform()
.baseimage()
)@func()
async example(): Promise<string> {
return dag
.terraform()
.baseImage()
}execute() 🔗
Return Type
Directory !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| terraformDir | Directory ! | - | No description provided |
| operation | String | "apply" | No description provided |
| variables | String | - | e.g., “name=patrick,food=schnitzel” |
| awsAccessKeyId | Secret | - | AWS S3/MinIO credentials |
| awsSecretAccessKey | Secret | - | No description provided |
| secretJsonVariables | Secret | - | No description provided |
| vaultRoleId | Secret | - | vaultRoleID |
| vaultSecretId | Secret | - | vaultSecretID |
| vaultToken | Secret | - | vaultToken |
| vaultAddr | String | - | Vault address (e.g. “https://vault.example.com”) |
| kubeConfig | Secret | - | Kubeconfig secret for Kubernetes backend access |
| kubeConfigPath | String | "/root/.kube/config" | Path to mount the kubeconfig inside the container (must match backend config_path) |
| exportTfOutput | Boolean | - | Run terraform output –json after the operation and write result to output.json |
| targets | String | - | Resource addresses to limit apply/destroy to, comma-separated, one -target each (e.g. ‘vault_kv_secret_v2.this[“kv/a”],null_resource.b’). Use it when the configuration manages more than the caller owns: an untargeted apply would also plan everything the caller’s inputs omit. |
| refuseDestroy | Boolean | - | Apply only if the plan deletes nothing. Plans to a file, aborts if any resource change contains “delete” (a replace does too), then applies exactly that plan – not a fresh one that could differ. apply only. |
| bindService | Service | - | A service to bind under bindServiceAlias – from the CLI
|
| bindServiceAlias | String | - | Hostname bindService is reachable under, e.g. the host in VAULT_ADDR. |
Example
dagger -m github.com/stuttgart-things/dagger/terraform@7228d65097efda4d607fbd7e335567b608d04f65 call \
execute --terraform-dir DIR_PATHfunc (m *MyModule) Example(terraformDir *dagger.Directory) *dagger.Directory {
return dag.
Terraform().
Execute(terraformDir)
}@function
def example(terraformdir: dagger.Directory) -> dagger.Directory:
return (
dag.terraform()
.execute(terraformdir)
)@func()
example(terraformDir: Directory): Directory {
return dag
.terraform()
.execute(terraformDir)
}output() 🔗
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| terraformDir | Directory ! | - | No description provided |
| awsAccessKeyId | Secret | - | No description provided |
| awsSecretAccessKey | Secret | - | No description provided |
| kubeConfig | Secret | - | Kubeconfig secret for Kubernetes backend access |
| kubeConfigPath | String | "/root/.kube/config" | Path to mount the kubeconfig inside the container (must match backend config_path) |
Example
dagger -m github.com/stuttgart-things/dagger/terraform@7228d65097efda4d607fbd7e335567b608d04f65 call \
output --terraform-dir DIR_PATHfunc (m *MyModule) Example(ctx context.Context, terraformDir *dagger.Directory) string {
return dag.
Terraform().
Output(ctx, terraformDir)
}@function
async def example(terraformdir: dagger.Directory) -> str:
return await (
dag.terraform()
.output(terraformdir)
)@func()
async example(terraformDir: Directory): Promise<string> {
return dag
.terraform()
.output(terraformDir)
}version() 🔗
Return Type
String ! Example
dagger -m github.com/stuttgart-things/dagger/terraform@7228d65097efda4d607fbd7e335567b608d04f65 call \
versionfunc (m *MyModule) Example(ctx context.Context) string {
return dag.
Terraform().
Version(ctx)
}@function
async def example() -> str:
return await (
dag.terraform()
.version()
)@func()
async example(): Promise<string> {
return dag
.terraform()
.version()
}