Common issues and their solutions.
Error Message:
Error: No value for required variable
│ on variables.tf line 1:
│ 1: variable "dbt_account_id" {
│
│ The root module input variable "dbt_account_id" is not set
Causes:
- Environment variables not loaded
- Incorrect variable name
- Missing
.envfile
Solutions:
- Load environment variables:
source .env
echo $TF_VAR_dbt_account_id # Verify it's set- Check variable names match:
# In .env, must be TF_VAR_<name>
export TF_VAR_dbt_account_id=12345
# In variables.tf
variable "dbt_account_id" { # Name matches after TF_VAR_
type = number
}- Pass directly:
terraform plan -var="dbt_account_id=12345"Error Message:
Error: Invalid value for input variable
│ The given value is not suitable for var.token_map
Cause: token_map isn't valid JSON.
Solutions:
# ❌ Multi-line won't work in .env
export TF_VAR_token_map='{
"key": "value"
}'
# ✅ Single line, use single quotes
export TF_VAR_token_map='{"key":"value","key2":"value2"}'
# ✅ Or use terraform.tfvars (HCL syntax)
token_map = {
key = "value"
key2 = "value2"
}Error Message:
Error: Error acquiring the state lock
│ Lock Info:
│ ID: abc123...
│ Operation: OperationTypePlan
│ Who: user@hostname
Causes:
- Previous Terraform run didn't finish
- Crashed Terraform process
- Concurrent runs
Solutions:
-
Wait for the other operation to complete
-
Verify no other runs are active:
# Check for terraform processes
ps aux | grep terraform- Force unlock (use carefully):
terraform force-unlock abc123!!! danger "Force Unlock Warning" Only force unlock if you're CERTAIN no other process is running. This can corrupt state.
Error Message:
Error: Module not installed
│ This configuration requires module "dbt_cloud"
Cause: Terraform modules not downloaded.
Solution:
terraform init
# Or if already initialized
terraform getError Message:
Error: dbt Cloud API error: 401 Unauthorized
Causes:
- Invalid API token
- Expired token
- Wrong dbt Cloud account
Solutions:
-
Regenerate token:
- Go to dbt Cloud Profile
- Create new API token
- Update
.envor secrets
-
Verify account ID:
# Check URL: https://cloud.getdbt.com/accounts/{ACCOUNT_ID}/
echo $TF_VAR_dbt_account_id- Check token format:
# Should start with 'dbtc_'
echo $TF_VAR_dbt_api_tokenError Message:
Error: dbt Cloud API error: 403 Forbidden
Cause: Token doesn't have required permissions.
Solutions:
- Use account-level token (not project-level)
- Check token permissions in dbt Cloud
- Create service account token with admin permissions
Error Message:
Error: Cannot find connection with key: "my_connection"
Cause: The environment's connection value doesn't match any globals.connections[].key (and isn't a valid numeric connection id or LOOKUP:… reference).
Solutions:
- Check your global connection keys under
globals:
globals:
connections:
- name: Databricks Production
key: databricks_prod # ← this is the key- Reference that key from the environment with
connection:
environments:
- name: Production
connection: databricks_prod # ← must match globals.connections[].key (unless using id / LOOKUP)Error Message:
Error: failed to parse YAML
│ yaml: line 10: did not find expected key
Causes:
- Invalid YAML syntax
- Incorrect indentation
- Missing quotes
Solutions:
- Validate YAML syntax:
# Use yamllint
yamllint dbt-config.yml
# Or online validator
# https://www.yamllint.com/- Check indentation (2 spaces, no tabs):
# ❌ Wrong
project:
name: "test" # 4 spaces
# ✅ Correct
project:
name: "test" # 2 spaces- Quote special characters:
# ❌ Wrong
name: My Project: Production
# ✅ Correct
name: "My Project: Production"Error Message:
Error: Missing required field
Cause: Required field not provided in YAML.
Solutions:
Check the YAML Schema for required fields:
environments:
- name: Production # Required
key: prod # Required
type: deployment # Required
deployment_type: production # Required for deployment envs
connection: my_conn # References globals.connections[].key
credential:
credential_type: databricks
schema: analyticsError Message:
Error: Invalid value for type: must be 'development' or 'deployment'
Cause: Used invalid value for a restricted field.
Solutions:
# ❌ Wrong
type: "prod" # Not a valid option
# ✅ Correct
type: "deployment" # Must be 'development' or 'deployment'Error Message:
Error: GitHub App installation not found
Causes:
- Invalid installation ID
- GitHub App not installed on repository
- Using wrong git_clone_strategy
Solutions:
-
Find installation ID:
- Go to GitHub Settings > Applications > dbt Cloud
- Check URL:
/settings/installations/{INSTALLATION_ID}
-
Install GitHub App:
- In dbt Cloud: Admin > Integrations > GitHub
- Click "Connect GitHub App"
- Authorize for your repositories
-
Update YAML:
repository:
remote_url: "https://github.com/org/repo.git"
git_clone_strategy: "github_app"
github_installation_id: 12345678 # Your installation IDError Message:
Error: GitLab project not found
Cause: Invalid GitLab project ID.
Solutions:
-
Find project ID:
- In GitLab: Project > Settings > General
- Look for "Project ID" (numeric value)
-
Update YAML:
repository:
remote_url: "https://gitlab.com/group/repo.git"
git_clone_strategy: "deploy_token"
gitlab_project_id: 9876543 # Numeric ID, not nameError Message:
Error: Token key 'prod_databricks_token' not found in token_map
Cause: YAML references a token key that doesn't exist in token_map.
Solutions:
Option A — Using environment_credentials (recommended):
# In YAML: environment with key: prod in project with key: analytics
environments:
- name: Production
key: prod
credential:
credential_type: databricks
catalog: main
schema: analytics# Key is "{project_key}_{env_key}"
export TF_VAR_environment_credentials='{"analytics_prod": {"credential_type": "databricks", "token": "dapi..."}}'Option B — Using token_map (legacy Databricks):
credential:
token_name: "prod_databricks_token" # This key...export TF_VAR_token_map='{"prod_databricks_token": "dapi_abc123"}'
# ↑ Must match exactlyProblem: CI/CD can't initialize Terraform.
Solutions:
- Check Terraform version:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.6.0 # Pin specific version- Verify backend access:
# Ensure CI has permissions to state bucket
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::123456789012:role/terraformProblem: Environment variables are undefined in CI/CD.
Solutions:
-
Verify secrets are defined:
- GitHub: Settings > Secrets and variables > Actions
- GitLab: Settings > CI/CD > Variables
- Azure DevOps: Pipelines > Library
-
Check secret names match:
env:
TF_VAR_dbt_account_id: ${{ secrets.DBT_ACCOUNT_ID }}
TF_VAR_dbt_token: ${{ secrets.DBT_TOKEN }}
TF_VAR_environment_credentials: ${{ secrets.ENVIRONMENT_CREDENTIALS }}
# Secret names must match exactly ↑- Ensure workflow has access:
# For protected branches
environment:
name: production # Must have access to this environment's secretsProblem: terraform plan runs for minutes.
Solutions:
- Use targeted plans:
terraform plan -target=module.dbt_cloud.module.jobs- Enable parallelism:
terraform plan -parallelism=10- Upgrade Terraform:
# Newer versions have performance improvements
terraform version
brew upgrade terraform # or similarProblem: State refresh takes a long time.
Solutions:
- Skip refresh when safe:
terraform plan -refresh=false- Use remote state caching:
terraform {
backend "s3" {
# Enable caching
skip_metadata_api_check = true
}
}Enable detailed logging:
# Set debug level
export TF_LOG=DEBUG
export TF_LOG_PATH=./terraform-debug.log
# Run terraform
terraform plan
# Review logs
cat terraform-debug.logStill stuck? Here's how to get support:
Search GitHub Issues for similar problems.
Include:
- Error message (full output)
- Terraform version:
terraform version - Module version: Check your
sourceURL - Minimal config that reproduces the issue
- What you've tried already
# DON'T DO THIS!
variable "dbt_token" {
default = "dbtc_xxxxx"
}# Make sure it's in .gitignore
echo ".env" >> .gitignore# Use service accounts, not personal tokens
# Generate at: dbt Cloud > Admin > Service Tokens# ❌ Bad
module "dbt" {
source = "git::https://github.com/..."
}
# ✅ Good
module "dbt" {
source = "git::https://github.com/...?ref=v1.0.0"
}Before deployment:
- Run
terraform fmt -check - Run
terraform validate - Review
terraform planoutput - Test in non-production first
- Have rollback plan ready
- Monitor logs during apply
- Verify resources in dbt Cloud UI
-
:material-book-open-variant:{ .lg .middle } Documentation
Review the full documentation
-
:material-github:{ .lg .middle } GitHub Issues
Report bugs or request features
-
:material-forum:{ .lg .middle } Discussions
Ask questions and share ideas