OpenTofu Support
TerraCi has first-class support for OpenTofu, the open-source Terraform fork.
Configuration
Switch to OpenTofu by updating .terraci.yaml:
yaml
gitlab:
terraform_binary: "tofu"
terraform_image: "ghcr.io/opentofu/opentofu:1.6"How It Works
When you set terraform_binary: "tofu", TerraCi:
- Sets
TERRAFORM_BINARY=tofuin the pipeline variables - Uses
${TERRAFORM_BINARY}in all generated scripts - Generates commands like
tofu init,tofu plan,tofu apply
Generated Pipeline
yaml
variables:
TERRAFORM_BINARY: "tofu"
default:
image: ghcr.io/opentofu/opentofu:1.6
before_script:
- ${TERRAFORM_BINARY} init
plan-platform-prod-vpc:
script:
- cd platform/prod/us-east-1/vpc
- ${TERRAFORM_BINARY} plan -out=plan.tfplan
# ...
apply-platform-prod-vpc:
script:
- cd platform/prod/us-east-1/vpc
- ${TERRAFORM_BINARY} apply plan.tfplan
# ...Official OpenTofu Images
Use official OpenTofu Docker images:
| Image | Description |
|---|---|
ghcr.io/opentofu/opentofu:latest | Latest stable |
ghcr.io/opentofu/opentofu:1.6 | Version 1.6.x |
ghcr.io/opentofu/opentofu:1.6.0 | Specific version |
Mixed Environments
If you have both Terraform and OpenTofu modules, you can override per-job:
yaml
# In your custom pipeline template
.tofu-job:
variables:
TERRAFORM_BINARY: "tofu"
image: ghcr.io/opentofu/opentofu:1.6
.terraform-job:
variables:
TERRAFORM_BINARY: "terraform"
image: hashicorp/terraform:1.6Then extend the generated jobs as needed.
State Compatibility
OpenTofu is compatible with Terraform state files. You can:
- Keep existing Terraform state files
- Migrate to OpenTofu without state changes
- Use the same S3/GCS backends
TerraCi's dependency resolution works identically for both.
Migration Guide
From Terraform to OpenTofu
Update
.terraci.yaml:yamlgitlab: terraform_binary: "tofu" terraform_image: "ghcr.io/opentofu/opentofu:1.6"Regenerate pipelines:
bashterraci generate -o .gitlab-ci.ymlTest with dry-run:
bashterraci generate --dry-runCommit and push
Gradual Migration
Migrate module by module using job overrides:
yaml
# Override specific jobs to use OpenTofu
apply-platform-prod-vpc:
extends: .tofu-jobVersion Compatibility
TerraCi works with:
| Tool | Supported Versions |
|---|---|
| Terraform | 0.12+ |
| OpenTofu | 1.0+ |
The HCL parsing is compatible with both.
Custom Binary Path
If your binary has a custom name or path:
yaml
gitlab:
terraform_binary: "/usr/local/bin/tofu-1.6"
before_script:
- ${TERRAFORM_BINARY} initEnvironment Variables
Set OpenTofu-specific environment variables:
yaml
gitlab:
variables:
TERRAFORM_BINARY: "tofu"
TF_CLI_CONFIG_FILE: "/etc/tofu/config.tfrc"
TOFU_LOG: "INFO"