teriac CLI OpenTofu and Terragrunt

OpenTofu and Terragrunt

Install, switch and pin OpenTofu and Terragrunt with the same commands as Terraform, and switch both tools at once in a Terragrunt project.

OpenTofu and Terragrunt are first-class tools in teriac. Every command you use for Terraform works for them with one flag.

OpenTofu

Every command works with OpenTofu through --provider tofu (or --provider opentofu, -p tofu):

teriac install latest --provider tofu
teriac use 1.8.0 --provider tofu
teriac list --remote --provider tofu
teriac current --provider tofu
teriac pin --provider tofu              # writes .opentofu-version
teriac auto-switch -p tofu
teriac plan --provider tofu
teriac exec 1.8.0 -p tofu -- validate

OpenTofu is stored apart from Terraform, in ~/.teriac/store/opentofu/, and runs as ~/.teriac/bin/tofu. Its downloads come from OpenTofu's GitHub releases and are checked against their published SHA256 checksums.

Which version OpenTofu uses

teriac auto-switch -p tofu reads, in order:

  1. .opentofu-version
  2. .tofu-version
  3. an opentofu or tofu line in .tool-versions
  4. .terraform-version
  5. terraform_version in terraform.tfstate
  6. required_version in .tf files

Running both

Terraform and OpenTofu can be active at the same time, since they're separate binaries:

teriac use 1.9.0
teriac use 1.8.0 -p tofu
terraform version   # Terraform v1.9.0
tofu version        # OpenTofu v1.8.0

Terragrunt

Terragrunt works the same way, with --provider terragrunt (or -p tg):

teriac install latest -p tg
teriac use 1.2.1 -p tg
teriac list --remote -p tg
teriac pin -p tg                        # writes .terragrunt-version
teriac auto-switch -p tg
teriac prune -p tg --keep 1

Terragrunt lives in ~/.teriac/store/terragrunt/ and runs as ~/.teriac/bin/terragrunt. Its downloads are checked against the release's SHA256SUMS too.

Which version Terragrunt uses

teriac auto-switch -p tg (and the shell hook) reads, in order:

  1. .terragrunt-version
  2. .tgswitchrc
  3. a terragrunt line in .tool-versions
  4. terragrunt_version_constraint in terragrunt.hcl / root.hcl

One cd, both tools

Terraform also reads terraform_version_constraint from terragrunt.hcl / root.hcl, so in a Terragrunt project one cd switches both tools:

# terragrunt.hcl
terraform_version_constraint  = "~> 1.9"
terragrunt_version_constraint = ">= 1.0, < 2.0"
cd live/prod/vpc
terraform version     # newest 1.9.x
terragrunt --version  # newest 1.x

Terragrunt with OpenTofu

Terragrunt runs whichever of terraform or tofu it's set up to use. teriac keeps both on your PATH, so pin OpenTofu with .opentofu-version next to terragrunt.hcl and the hook switches it along with Terragrunt.

In teriac server

teriac server uses the same rules: each project is planned with the exact Terraform, Terragrunt and OpenTofu versions it pins. A repo can also set them per project in teriac.yaml with engine, version and terragrunt_version.