# Override module source to test local changescd environments/dev/vpcterragrunt plan --terragrunt-source ../../../modules/vpc-local# Apply with local moduleterragrunt apply --terragrunt-source ../../../modules/vpc-local# Reset to remote sourceterragrunt plan --terragrunt-source-update
사용 사례 2: 모듈 의존성 관리
# List all resources in stateterragrunt state list# Move resource to new addressterragrunt state mv aws_instance.old aws_instance.new# Import existing AWS resourceterragrunt import aws_instance.web i-1234567890abcdef0# Remove resource from state (keeps actual resource)terragrunt state rm aws_instance.temporary# Pull remote state for inspectionterragrunt state pull > backup.tfstate
사용 사례 3: 로컬 모듈 개발
# Enable debug loggingexport TERRAGRUNT_LOG_LEVEL=debugterragrunt plan# Run with trace-level loggingterragrunt apply --terragrunt-log-level trace 2>&1 | tee debug.log# Validate all configurationsterragrunt run-all validate# Check formatting issuesterragrunt hclfmt --terragrunt-check# Test configuration renderingterragrunt render-json | jq '.'
사용 사례 4: 상태 관리 및 마이그레이션
terragrunt.hcl
사용 사례 5: 디버깅 및 문제 해결
include
모범 사례
DRY 원칙 사용: 백엔드 구성을 루트에 보관하고?ref=v1.0.0중복을 방지하기 위해 dependency블록을 사용하여 자식 모듈에 포함
모듈 버전 관리: 항상 모듈 소스를 특정 버전이나 태그에 고정 (예: find_in_parent_folders(), get_aws_account_id(), and path_relative_to_include() for dynamic configuration
Use mock outputs: Define mock_outputs in dependency blocks to enable validation and planning without requiring all dependencies to be applied first
Organize by environment: Structure directories by environment (dev/staging/prod) with shared configuration at the root level for consistency
Enable state locking: Always configure DynamoDB tables for state locking when using S3 backend to prevent concurrent modification conflicts
Use run-all carefully: Test with run-all plan before run-all apply and consider using --terragrunt-parallelism to control concurrent executions
Generate provider configs: Use generate blocks to create provider configurations dynamically, ensuring consistency across modules
Implement hooks for automation: Use before_hook and after_hook to automate tasks like validation, notifications, or compliance checks
Troubleshooting
문제
솔루션
Error: “No Terraform configuration files”
Ensure terraform.source is correctly specified in terragrunt.hcl and the source path exists. Run terragrunt init to download modules.
Backend initialization fails
Check AWS credentials and permissions. Verify S3 bucket and DynamoDB table exist or set skip_bucket_creation = false in remote_state config.
Dependency outputs not found
Ensure dependency module is applied first. Use mock_outputs for planning without dependencies. Check config_path points to correct directory.
”Working directory already exists” error
Clear Terragrunt cache: rm -rf .terragrunt-cache then run terragrunt init again. Or use --terragrunt-source-update flag.
Module source not updating
Force source update with terragrunt init --terragrunt-source-update or delete .terragrunt-cache directory to clear cached modules.
State lock acquisition timeout
다른 프로세스가 잠금을 보유하고 있습니다. 완료를 기다리거나 DynamoDB 테이블에서 잠금을 수동으로 해제하세요. 충돌한 프로세스를 확인하세요.
”Module not found” with relative paths
Use find_in_parent_folders() to locate root config. Ensure relative paths account for Terragrunt’s working directory structure.
Run-all commands fail partially
Check individual module errors with --terragrunt-log-level debug. Verify dependencies are correctly defined. Use --terragrunt-ignore-dependency-errors cautiously.
Permission denied errors on AWS
Verify IAM role/user has required permissions. Check if role_arn in provider config is correct. Ensure MFA token is valid if required.
Circular dependency detected
Review dependency blocks to identify circular references. Restructure modules to break the cycle. Use terragrunt graph-dependencies to visualize.
Variables not being passed correctly
Check inputs block syntax in terragrunt.hcl. Verify variable names match module definitions. Use terragrunt render-json to inspect final config.
Performance issues with many modules
Adjust --terragrunt-parallelism to optimize concurrent executions. Consider splitting into smaller module groups. Use --terragrunt-include-dir for selective runs.
Quick Reference: Terragrunt vs Terraform Commands
Terragrunt 명령어
동등한 Terraform
주요 차이점
terragrunt init
terraform init
Auto-configures backend from terragrunt.hcl
terragrunt plan
terraform plan
Terragrunt 관리 입력 및 종속성 포함
terragrunt apply
terraform apply
프로세스 종속성을 처리하고 구성을 생성합니다
terragrunt run-all apply
I apologize, but there is no text provided to translate. Could you please share the specific English text you would like me to translate to Korean?
의존성 순서에 따라 여러 모듈에서 실행됩니다
terragrunt output
terraform output
여러 모듈의 출력을 집계할 수 있음
This site uses cookies for analytics and to improve your experience.
See our Privacy Policy for details.