terraci init
Initialize a TerraCi configuration file.
Synopsis
terraci init [flags]Description
The init command creates a .terraci.yaml configuration file. By default, it launches an interactive TUI wizard that guides you through configuration choices. Use --ci for non-interactive mode suitable for automation, or pass specific flags to skip the wizard.
Flags
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--force | -f | bool | false | Overwrite existing configuration |
--ci | bool | false | Non-interactive mode (skip TUI wizard) | |
--provider | string | CI provider: gitlab or github | ||
--binary | string | Terraform binary: terraform or tofu | ||
--pattern | string | Directory structure pattern |
When any of --provider, --binary, or --pattern is provided, the wizard is automatically skipped and non-interactive mode is used.
Examples
Interactive Mode (Default)
terraci initThis launches a TUI wizard with the following groups:
- Basics — CI provider (GitLab CI or GitHub Actions), Terraform binary (Terraform or OpenTofu)
- Structure — directory structure pattern
- Pipeline Options — configure plan jobs
- Plugin groups — dynamic groups contributed by enabled plugins (gitlab/github image, summary, cost, policy, tfupdate, etc.)
Non-Interactive Mode
terraci init --ciCreates .terraci.yaml with default values without prompting.
Provider Selection
# Generate config for GitHub Actions
terraci init --provider github
# Generate config for GitLab CI
terraci init --provider gitlabWhen --provider github is used, the generated config will have a github: section (with runs_on, steps_before, etc.) and no gitlab: section. When --provider gitlab is used, the config will have a gitlab: section (with image, tags, etc.) and no github: section.
OpenTofu Setup
terraci init --provider gitlab --binary tofuThis automatically selects the appropriate image (ghcr.io/opentofu/opentofu:1.6) and for GitHub Actions, uses opentofu/setup-opentofu@v1 instead of hashicorp/setup-terraform@v3.
Custom Pattern
terraci init --pattern "{team}/{stack}/{datacenter}/{component}"Full Non-Interactive Example
terraci init --provider github --binary tofu --pattern "{service}/{environment}/{region}/{module}"Force Overwrite
terraci init --forceOverwrites existing .terraci.yaml without prompting.
Different Directory
terraci -d /path/to/project initCreates configuration in specified directory.
Generated Configuration
GitLab Provider
When --provider gitlab (or default), creates:
structure:
pattern: "{service}/{environment}/{region}/{module}"
execution:
binary: terraform
extensions:
gitlab:
image:
name: hashicorp/terraform:1.6
stages_prefix: deployGitHub Provider
When --provider github, creates:
structure:
pattern: "{service}/{environment}/{region}/{module}"
execution:
binary: terraform
extensions:
github:
runs_on: ubuntu-latest
permissions:
contents: read
pull-requests: write
job_defaults:
steps_before:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3Backend configuration (S3, GCS, etc.) is not generated by
terraci init— TerraCi reads existingterraform { backend "..." }blocks from your modules to disambiguate state keys; nothing is added to.terraci.yaml.
What Gets Created
The command creates:
.terraci.yamlin the current (or specified) directory
It does NOT modify:
- Existing Terraform files
- CI configuration files
- Any other project files
After Initialization
Review the configuration
bashcat .terraci.yamlCustomize for your project
- Adjust the pattern to match your structure
- Update the Docker image or runner labels
- Add exclude patterns
- Configure backend settings
Validate
bashterraci validateGenerate your first pipeline
bashterraci generate --dry-run # For GitLab: terraci generate -o .gitlab-ci.yml # For GitHub: terraci generate -o .github/workflows/terraform.yml
Troubleshooting
File Already Exists
Error: config file already exists: .terraci.yaml (use --force to overwrite)Solution: Use --force or manually edit the existing file.
Permission Denied
Error: permission denied: .terraci.yamlSolution: Check file permissions and ownership.
See Also
- Configuration Overview -- full configuration reference for .terraci.yaml
- Getting Started -- step-by-step guide to set up TerraCi