Troubleshooting
Common issues and solutions when working with nx-terraform.
Installation Issues
Plugin Not Found
Symptoms:
- Error: "Plugin not found" or "Cannot find module 'nx-terraform'"
- Generators not available
Solutions:
-
Reinstall the plugin:
nx add nx-terraform -
Verify installation:
nx list nx-terraform -
Check plugin registration in
nx.json:{
"plugins": [
{
"plugin": "nx-terraform",
"options": {}
}
]
} -
Clear Nx cache:
nx reset
Project Discovery Issues
Project Not Discovered
Symptoms:
- Project doesn't appear in
nx show projects - No targets available for the project
- Error: "Project not found"
Solutions:
-
Check project configuration:
# Verify project.json exists
ls packages/my-project/project.json
# Check that metadata['nx-terraform'].projectType is set
cat packages/my-project/project.json | jq '.metadata["nx-terraform"].projectType'Discovery is triggered by
project.json; the project must havemetadata['nx-terraform'].projectTypeset tobackend,stateful, ormodule. Use the plugin generators to create projects, or add this metadata manually. -
Verify file locations:
project.jsonmust exist in the project root- Directory structure must be correct (Terraform files such as
main.tftypically live in the same directory)
-
Check plugin is registered:
cat nx.json | grep nx-terraform -
Restart Nx daemon:
nx reset
Wrong Project Type
Symptoms:
- Project discovered but wrong type
- Targets not working as expected
- Incorrect caching behavior
Solutions:
-
Check
projectTypeinproject.json:{
"projectType": "application" // or "library"
} -
Check metadata: Ensure
metadata['nx-terraform'].projectTypeis set. For stateful projects, ensuretargets['terraform-init'].metadata.backendProjectis set (see Configuration).{
"metadata": {
"nx-terraform": {
"projectType": "module"
}
}
} -
Use sync generator:
nx g nx-terraform:sync-terraform-metadata
Backend Issues
Backend Connection Errors
Symptoms:
- Error: "Failed to get existing workspaces"
- Error: "Backend configuration error"
- Cannot initialize stateful projects
Solutions:
-
For AWS S3 backend:
- Ensure AWS credentials are configured:
aws configure
# Or set environment variables:
export AWS_ACCESS_KEY_ID=your-key
export AWS_SECRET_ACCESS_KEY=your-secret - Verify the backend project has been applied:
nx run terraform-setup:terraform-apply - Check that
backend.configexists:ls packages/terraform-setup/backend.config
- Ensure AWS credentials are configured:
-
For local backend:
- Verify backend configuration in
backend.tf - Check file permissions
- Verify backend configuration in
-
Verify backend project exists:
nx show project terraform-setup
Backend Already Exists (AWS S3)
Symptoms:
- Error: "Bucket already exists"
- Terraform import errors
Solutions:
-
Use unique bucket name prefix:
nx g nx-terraform:terraform-backend my-backend \
--backendType=aws-s3 \
--bucketNamePrefix=myorg-terraform -
Manually specify existing bucket (if reusing)
-
Import existing bucket (advanced)
AWS Credentials Not Configured
Symptoms:
- Error: "No valid credential sources found"
- Authentication failures
Solutions:
-
Configure AWS CLI:
aws configure -
Set environment variables:
export AWS_ACCESS_KEY_ID=your-key
export AWS_SECRET_ACCESS_KEY=your-secret
export AWS_REGION=us-east-1 -
Use IAM roles (for EC2/ECS)
Permission Denied
Symptoms:
- Error: "Access Denied" or "Permission denied"
- Cannot create S3 buckets or DynamoDB tables
Solutions:
-
Check IAM permissions. Your AWS credentials need:
s3:CreateBuckets3:PutObjects3:GetObjectdynamodb:CreateTable(if using state locking)dynamodb:PutItemdynamodb:GetItem
-
Verify IAM user/role has correct policies
-
Check bucket policies (if bucket exists)
Dependency Issues
Dependency Not Detected
Symptoms:
- Project runs before dependency
- Errors about missing resources
- Wrong execution order
Solutions:
-
Check module reference syntax:
module "networking" {
source = "../../networking" // Must use relative path
} -
Verify project names match directory names
-
Check
terraform-inittarget options are correct (backend project name):{
"targets": {
"terraform-init": {
"metadata": {
"backendProject": "terraform-setup"
}
}
}
} -
Verify projects are discovered:
nx show projects
Circular Dependency
Symptoms:
- Nx error about circular dependencies
- Projects can't determine execution order
Solutions:
-
Review module references - identify the cycle
-
Break circular dependencies:
- Extract common code to shared module
- Use data sources instead of module references
- Restructure project dependencies
-
Example fix:
// Before (circular):
// app-a uses app-b, app-b uses app-a
// After (fixed):
// app-a uses shared, app-b uses shared
Wrong Execution Order
Symptoms:
- Backend not applied before infrastructure
- Modules not validated before use
Solutions:
-
Check target dependencies:
nx show project my-infra --json | jq '.targets["terraform-init"].dependsOn' -
Verify project dependencies:
nx graph -
Review
dependsOnconfiguration in project.json
Configuration Issues
Configuration Not Found
Symptoms:
- Error: "Missing tfvars file"
- Variables not applied
Solutions:
-
Verify
tfvarsfile exists:ls packages/my-infra/tfvars/dev.tfvars -
Check file naming matches configuration:
--configuration=dev→tfvars/dev.tfvars--configuration=prod→tfvars/prod.tfvars
-
Verify file is in project directory
Variables Not Applied
Symptoms:
- Variables not taking effect
- Wrong values used
Solutions:
-
Check
tfvarsfile syntax - must be valid HCL -
Verify variable names match in
variables.tfandtfvarsfile -
Check for typos in variable names
-
Verify configuration is used:
nx run my-infra:terraform-plan --configuration=dev
Caching Issues
Cache Not Working
Symptoms:
- Operations always run
- No cache hits
Solutions:
-
Check cache is enabled for the operation (see Caching Guide)
-
Verify file inputs haven't changed:
- Check
.tfand.tfvarsfiles - Check
backend.config(if using remote backend)
- Check
-
Clear and rebuild cache:
nx reset
Stale Cache
Symptoms:
- Results don't match expectations
- Cache shows old results
Solutions:
-
Clear cache:
nx reset -
Check for file changes that should invalidate cache
-
Verify cache inputs are correct
Terraform-Specific Issues
Provider Not Found
Symptoms:
- Error: "Provider not found"
- Cannot download providers
Solutions:
-
Check provider configuration in
provider.tf -
Verify Terraform version compatibility
-
Check network connectivity (for provider downloads)
-
Clear Terraform cache:
rm -rf .terraform
nx run my-project:terraform-init
State Lock Errors
Symptoms:
- Error: "Error acquiring the state lock"
- Cannot apply changes
Solutions:
-
Check if another process is running Terraform
-
For DynamoDB locks:
- Check DynamoDB table exists
- Verify permissions
- Manually release lock if needed (advanced)
-
Wait for lock to release (if another process is running)
State File Conflicts
Symptoms:
- State conflicts between environments
- Wrong state file used
Solutions:
-
Ensure each environment uses different state key:
dev-infra/terraform.tfstateprod-infra/terraform.tfstate
-
Verify backend configuration is correct
-
Don't copy state files between environments
Getting More Help
Enable Debug Logging
export TF_LOG=DEBUG
nx run my-project:terraform-plan
Check Nx Logs
nx show project my-project --json
View Project Graph
nx graph
Common Resources
Still Having Issues?
If you're still experiencing problems:
- Check the GitHub Issues
- Review the Reference Documentation
- Open a new issue with:
- Error messages
- Steps to reproduce
- Nx and Terraform versions
- Relevant configuration files