OpenTofu Provisioner
Runs a step with OpenTofu. Source: provisioner-opentofu.
Structure​
The step's path holds an OpenTofu module.
To use a dependency lock file (.terraform.lock.hcl), keep it in the module directory when you publish, and check it into source control.
State is kept in Massdriver's HTTP state backend, one state per instance and step. The provisioner writes the backend configuration, so the module must not declare a backend.
Actions​
| Action | Runs |
|---|---|
plan | tofu plan, then Checkov against the plan |
provision | tofu plan, Checkov, tofu apply, then publishes resources |
decommission | tofu plan -destroy, tofu apply, then deletes the step's resources |
Tooling​
- Checkov scans the plan for policy and compliance violations on
planandprovision.
Configuration​
| Key | Type | Default | Description |
|---|---|---|---|
log_level | string | Sets TF_LOG: TRACE, DEBUG, INFO, WARN, ERROR, JSON, or OFF. | |
json | boolean | false | Adds -json to plan and apply. |
checkov.enable | boolean | true | Runs Checkov. |
checkov.quiet | boolean | true | Shows only failed checks (--quiet). |
checkov.halt_on_failure | boolean | false | Fails the deployment on a failed check (drops --soft-fail). |
ssh.private_key | string | SSH private key for private module repositories. When set, the provisioner rewrites https:// git URLs to SSH. |
Inputs​
OpenTofu reads variables from JSON files, so the provisioner copies params.json and connections.json into the module directory unchanged, as _params.auto.tfvars.json and _connections.auto.tfvars.json. Each param and each dependency is a variable of the same name.
mass bundle build writes _massdriver_variables.tf with a typed variable declaration for each param and dependency. To reshape a value, use a locals block.
Resources​
A step publishes the resources declared in the bundle's resources block in one of two ways.
massdriver_resource​
The massdriver_resource resource of the Massdriver provider:
resource "massdriver_resource" "bucket" {
field = "bucket"
name = "S3 bucket ${aws_s3_bucket.main.bucket}"
resource = jsonencode({
arn = aws_s3_bucket.main.arn
region = var.region
})
}
field is the resource's name in massdriver.yaml. resource is the payload, which must match the resource type's schema.
jq templates​
After tofu apply, the provisioner renders a jq template for each resource. The template is steps[].resources.<name>.template in massdriver.yaml, or a resource_<name>.jq file in the module directory. See Provisioners: Resources.
The template reads params, connections, envs, secrets, and outputs, where outputs holds the module's outputs.
Take a bucket bundle with one param, one dependency, and one resource:
steps:
- path: src
provisioner: opentofu
params:
required:
- region
properties:
region:
type: string
dependencies:
aws_authentication:
resource_type: aws-iam-role@~1
required: true
resources:
bucket:
resource_type: aws-s3-bucket@~1
required: true
Output only the values the resource needs:
output "bucket_arn" {
value = aws_s3_bucket.main.arn
}
The template's input is:
{
"params": {
"region": "us-east-1"
},
"connections": {
"aws_authentication": {
"arn": "arn:aws:iam::012345678910:role/role_name",
"external_id": "s0mes3cr3tv@lue"
}
},
"envs": {},
"secrets": {},
"outputs": {
"bucket_arn": "arn:aws:s3:::the_bucket_name"
}
}
Build the resource in src/resource_bucket.jq:
{
"arn": .outputs.bucket_arn,
"region": .params.region
}
Or inline, in massdriver.yaml:
steps:
- path: src
provisioner: opentofu
resources:
bucket:
template: '{arn: .outputs.bucket_arn, region: .params.region}'
To build the whole payload in OpenTofu instead, output it as an object and return it from the template, such as .outputs.bucket.