Skip to content

terraform

The terraform archetype is for Terraform and OpenTofu modules: cloud-accounts environments and safe-settings. It runs init, plan and apply, validates and lints, and generates module docs.

# mise.toml
[task_config]
includes = [".mise/common/tasks.toml", ".mise/archetypes/terraform/tasks.toml"]
# Makefile (often in environments/<name>/)
include .mise/archetypes/terraform/include.mk

Every task runs in the invoking directory

Terraform tasks run in {{cwd}}. The invoking Makefile usually lives below the repo root, in environments/<name>/, and plan and apply must target that module. cloud-accounts keeps its own root fan-out (recursing into each environment), and only the leaf environments adopt the archetype.

The prose passes still run from the repo root, so a repo-wide Markdown sweep rides along with each module's fmt and lint.

Tasks

Task What it does
init terraform init, through tf-run.sh.
plan terraform plan -out=plan.tfplan, through tf-run.sh.
apply plan, then terraform apply plan.tfplan, through tf-run.sh.
fmt terraform fmt -recursive, then prose format.
lint backend-less init, terraform validate ., tflint, containers, shell, workflows, prose.
docs terraform-docs ..
ci lint, docs, docs-build.
pr fmt, lint, docs, docs-build.

lint initialises the module with -backend=false -input=false first: validate needs an initialised module, but no remote state.

No license tasks

terraform is the one archetype without the license passes, because addlicense would stamp headers into .tf files. Its pr ends with docs rather than commit.

OpenTofu

Set the terraform_binary knob and pin OpenTofu in the repo's root [tools]. The shared pins only cover terraform:

[tools]
"aqua:opentofu/opentofu" = "…"

[vars]
terraform_binary = "tofu"

Every task then drives tofu instead of terraform.

Variables and secrets

Plain, non-secret variables — a service account to impersonate, a region — go in the module's own mise.toml:

[env]
GOOGLE_IMPERSONATE_SERVICE_ACCOUNT = "terraform-apply@o-foundation-1234.iam.gserviceaccount.com"

mise loads [env] from the invoking directory into every task, so they reach terraform with no wrapper (and into the shell on cd, for running terraform by hand). mise expands $VARS and {{ … }} templates in these values.

Secrets go in the module's fnox.toml. archetypes/terraform/scripts/tf-run.sh wraps every state-touching invocation (init, plan, apply and lint's backend-less init):

if [ -f fnox.toml ]; then
  exec fnox exec -- "$@"
fi
exec "$@"
  • When the module directory has a fnox.toml, its secrets are injected through fnox exec.
  • Otherwise the command runs untouched.

fnox is a shared lazy pin (see Secrets with fnox), so it's installed the first time a module with a fnox.toml runs a task. CI runs the wrapper too, through lint's backend-less init. A secret the runner can't resolve only warns by default, so lint still runs. A module that sets if_missing = "error" needs vault access in CI, or FNOX_IF_MISSING=warn on the job.

dotty env migrate converts a legacy .env.dotty into both files: its plain lines into mise.toml, its {{ dotty://… }} references into fnox.toml.

Knobs

Knob Default Meaning
terraform_binary terraform The binary every task drives (tofu for OpenTofu).

Source

archetypes/terraform/tasks.toml
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# terraform — archetype for a Terraform module (cloud-accounts environments,
# safe-settings). Generalises cloud-accounts' cloud.mk.
#
# Include AFTER common/tasks.toml in the consumer's root mise.toml:
#   [task_config]
#   includes = [".mise/common/tasks.toml", ".mise/archetypes/terraform/tasks.toml"]
#
# Every task runs in {{cwd}}: the invoking Makefile typically lives below the
# repo root (environments/<name>/), and plan/apply must target that module.
# cloud-accounts keeps its root fan-out aggregator (environments/<name>
# recursion) unchanged; only the leaf environments adopt this archetype.
#
# scripts/tf-run.sh wraps every state-touching invocation: it injects
# secrets via fnox only when the module directory carries a fnox.toml and
# calls the binary directly otherwise. Plain, non-secret variables live in the
# module's mise.toml [env] and reach every task without the wrapper. fnox is a
# shared lazy pin (see the library config header), so no task carries a
# `tools` map for it; a module without a fnox.toml never installs it.
#
# {{vars.terraform_binary}} picks the driver: "terraform" (the shared pin) by
# default; an OpenTofu repo sets it to "tofu" and adds the opentofu pin to its
# root mise.toml [tools].
#
# The house prose format/lint is part of fmt/lint like every archetype; it
# runs from the repo root even when make is invoked in an environment
# subdirectory, so a repo-wide README sweep rides along with each module.
# The license tasks are deliberately NOT wired in: addlicense would stamp
# headers into .tf files.

[init]
description = "initialise the terraform module"
dir = "{{cwd}}"
run = "{{config_root}}/.mise/archetypes/terraform/scripts/tf-run.sh {{vars.terraform_binary}} init"

# Backend-less init used by lint (validate needs an initialised module but no
# remote state).
[init-no-backend]
hide = true
dir = "{{cwd}}"
run = "{{config_root}}/.mise/archetypes/terraform/scripts/tf-run.sh {{vars.terraform_binary}} init -backend=false -input=false"

[plan]
description = "plan infrastructure changes"
dir = "{{cwd}}"
run = "{{config_root}}/.mise/archetypes/terraform/scripts/tf-run.sh {{vars.terraform_binary}} plan -out=plan.tfplan"

[apply]
description = "apply infrastructure changes"
dir = "{{cwd}}"
run = [{ task = "plan" }, "{{config_root}}/.mise/archetypes/terraform/scripts/tf-run.sh {{vars.terraform_binary}} apply plan.tfplan"]

# Auto-format pass wired into `fmt`.
[tf-fmt]
hide = true
dir = "{{cwd}}"
run = "{{vars.terraform_binary}} fmt -recursive"

# Check-mode pass wired into `lint`.
[tf-lint]
hide = true
dir = "{{cwd}}"
run = [{ task = "init-no-backend" }, "{{vars.terraform_binary}} validate .", "tflint"]

# Doc generation wired into `docs`. terraform-docs is a lazy tool, so a bare
# `terraform-docs` goes through its bootstrap shim — a symlink to the first
# `mise` on PATH that dispatches on argv[0]. Under containerbase (the Renovate
# image, which runs this task as a postUpgradeTask) that `mise` is a bash
# wrapper that drops argv[0], so the shim runs as `mise .` ("no task . found").
# `mise x` installs the pinned version up front and puts the real binary on
# PATH, bypassing the shim; versionless, so config.toml stays the single pin.
[tf-docs]
hide = true
dir = "{{cwd}}"
run = "mise x aqua:terraform-docs/terraform-docs -- terraform-docs ."

[fmt]
description = "terraform fmt -recursive + prose format"
run = [{ task = "tf-fmt" }, { task = "fmt-prose" }]

[lint]
description = "terraform validate + tflint + prose, container, shell and workflow checks"
run = [
  { task = "tf-lint" },
  { task = "lint-containers" },
  { task = "lint-shell" },
  { task = "lint-workflows" },
  { task = "lint-prose" },
]

[docs]
description = "generate module docs (terraform-docs)"
run = [{ task = "tf-docs" }]

[ci]
description = "the checks the reusable CI workflow runs"
run = [{ task = "lint" }, { task = "docs" }, { task = "docs-build" }]

[pr]
description = "full local gate before a pull request"
run = [{ task = "fmt" }, { task = "lint" }, { task = "docs" }, { task = "docs-build" }]