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.22.0
Entrypoint
Return Type
Terraform
Example
dagger -m github.com/stuttgart-things/dagger/terraform@2820e73fb4c0dc247fb7f369194859e9dcb81691 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@2820e73fb4c0dc247fb7f369194859e9dcb81691 call \
base-image
func (m *MyModule) Example(ctx context.Context) string {
return dag.
Terraform().
BaseImage(ctx)
}
@function
async def example() -> str:
return await (
dag.terraform()
.base_image()
)
@func()
async example(): Promise<string> {
return dag
.terraform()
.baseImage()
}
version() 🔗
Return Type
String !
Example
dagger -m github.com/stuttgart-things/dagger/terraform@2820e73fb4c0dc247fb7f369194859e9dcb81691 call \
version
func (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()
}
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" |
secretJsonVariables | Secret | - | No description provided |
vaultRoleId | Secret | - | vaultRoleID |
vaultSecretId | Secret | - | vaultSecretID |
vaultToken | Secret | - | vaultToken |
Example
dagger -m github.com/stuttgart-things/dagger/terraform@2820e73fb4c0dc247fb7f369194859e9dcb81691 call \
execute --terraform-dir DIR_PATH
func (m *MyModule) Example(terraformDir *dagger.Directory) *dagger.Directory {
return dag.
Terraform().
Execute(terraformDir)
}
@function
def example(terraform_dir: dagger.Directory) -> dagger.Directory:
return (
dag.terraform()
.execute(terraform_dir)
)
@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 |
Example
dagger -m github.com/stuttgart-things/dagger/terraform@2820e73fb4c0dc247fb7f369194859e9dcb81691 call \
output --terraform-dir DIR_PATH
func (m *MyModule) Example(ctx context.Context, terraformDir *dagger.Directory) string {
return dag.
Terraform().
Output(ctx, terraformDir)
}
@function
async def example(terraform_dir: dagger.Directory) -> str:
return await (
dag.terraform()
.output(terraform_dir)
)
@func()
async example(terraformDir: Directory): Promise<string> {
return dag
.terraform()
.output(terraformDir)
}