Terraform in env zero
env zero supports Terraform as an alternative to OpenTofu, allowing you to use HashiCorp’s official Terraform binary for your infrastructure deployments. While OpenTofu is the default, you can easily switch to Terraform when needed.Configuration options
Terraform version selection
To use Terraform instead of OpenTofu:- Navigate to your template settings
- Open the Advanced settings section
- Select Terraform from the TF binary dropdown
- Choose your preferred Terraform version

Working directory
Configure the working directory where your Terraform configuration files are located:- Root directory: Use the repository root (default)
- Subdirectory: Specify a path relative to the repository root
If your Terraform files are in a subdirectory, specify the path in the Working Directory field under Advanced settings.
Terraform-specific features
State management
Terraform uses state files to track infrastructure resources:- Local state: Stored temporarily during deployment
- Remote state: Recommended for production environments using backends
- State locking: Prevents concurrent modifications using DynamoDB or similar
State persistenceenv zero stores the local state between deployments by default. For production environments, configure a remote backend in your Terraform configuration to ensure state persistence and team collaboration.
Variable handling
Terraform supports multiple variable input methods with clear precedence:- Command-line variables:
-var
flags (highest precedence) - Environment variables:
TF_VAR_*
prefixed variables - Variable files:
.tfvars
files - Default values: Defined in variable blocks (lowest precedence)
Provider configuration
Configure Terraform providers in your configuration files:main.tf
Deployment workflow
env zero follows Terraform’s standard deployment workflow:- Initialize:
terraform init
- Download providers and modules - Plan:
terraform plan
- Generate execution plan - Apply:
terraform apply
- Execute the planned changes - Destroy:
terraform destroy
- Remove resources (when needed)
Plan and apply process
The plan step generates a detailed execution plan showing what changes will be made. The apply step uses this plan to make the actual changes to your infrastructure.env zero stores plan files between the plan and apply steps to ensure consistency and allow for review and approval workflows.
Best practices
Remote backend configuration
Configure a remote backend for state management:backend.tf
Module usage
Organize your infrastructure using Terraform modules:main.tf
Variable management
Use consistent variable naming and types:variables.tf
Advanced features
Workspaces
Terraform workspaces allow you to manage multiple environments:env zero automatically manages Terraform workspaces based on your environment configuration.
Data sources
Use data sources to fetch information about existing resources:data.tf
Outputs
Define outputs to expose important resource information:outputs.tf
Troubleshooting
Common issues
Provider version conflicts- Ensure provider versions are compatible with your Terraform version
- Check the Terraform provider compatibility matrix
- Use remote backends for production environments
- Enable state locking to prevent concurrent modifications
- Regularly backup your state files
- Check variable precedence order
- Verify environment variables are set correctly in env zero
- Use
terraform console
to debug variable values
Debugging deployments
Enable detailed logging by setting theTF_LOG
environment variable:
TF_LOG=DEBUG
- Most verbose loggingTF_LOG=INFO
- Standard information levelTF_LOG=WARN
- Warning and error messages only
Set the
TF_LOG
environment variable in your template’s environment variables section for detailed Terraform execution logs.Common error messages
“Error: No such file or directory”- Verify the working directory path is correct
- Check that Terraform files exist in the specified location
- Ensure proper backend configuration
- Check backend credentials and permissions
- Verify required providers are declared
- Check provider version constraints
Migration considerations
From OpenTofu to Terraform
If migrating from OpenTofu to Terraform:- Configuration compatibility: Most configurations work without changes
- State files: Compatible format, but consider backing up first
- Provider versions: Verify compatibility with Terraform version
- Testing: Test in a non-production environment first
Migration planningAlways test migrations in a development environment before applying to production infrastructure.