I have a modular Terraform structure managed with Terragrunt, and I want to maintain the modularity of my configuration. However, I need to create and manage the state file and acquire locks at the parent directory level.
Here’s my current project structure:
.
├── backend-config.yml
├── backend.tf
├── core-dns-csi-driver-addon
│ ├── terragrunt.hcl
├── eks
│ ├── terragrunt.hcl
├── karpenter
│ ├── terragrunt.hcl
├── kube-proxy-vpc-cni-addon
│ ├── terragrunt.hcl
├── local-swarm-nodegroup
│ ├── terragrunt.hcl
├── loki
│ ├── terragrunt.hcl
├── metrics-server
│ ├── terragrunt.hcl
├── provider.tf
├── storageclass
│ ├── terragrunt.hcl
├── terragrunt.hcl # Parent-level configuration
├── update_yaml.py
└── vpc
├── terragrunt.hcl
Requirements:
What I Have Tried:
Terragrunt Root Configuration:
Created a root terragrunt.hcl file with the shared back-end configuration:
remote_state {
backend = "s3"
config = {
bucket = "my-terraform-state"
key = "terraform/parent-level-state.tfstate"
region = "us-east-1"
dynamodb_table = "eks-locks"
encrypt = true
}
}
Child Module Configuration:
Referenced the parent configuration in each module's terragrunt.hcl file:
include {
path = find_in_parent_folders()
}
How can I configure Terragrunt to enforce a single state file and locking mechanism at the parent level while keeping the modular structure intact?
How can I apply and destroy at module level, keeping state file intact at parent level?
Is there a better approach to managing modular Terraform configurations with shared state and lock files at the parent level?