Welcome to Lab 4. In this lesson, you’ll configure Terragrunt to deploy and manage an AWS VPC module. You have access to an AWS account—follow the steps below to set up credentials, initialize modules, enforce safeguards, and customize Terragrunt settings for a robust infrastructure workflow.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Keep your AWS credentials secure. You can retrieve them with:Or log in via the provided link using your username and password. Consider opening a second terminal tab to streamline copy-and-paste.
1. Configure the VPC Module
InTerraform stack/VPC/terragrunt.hcl, reference the remote AWS VPC module (v5.8.1) from the Terraform Registry:
2. Configure a Custom Terragrunt Cache
Terragrunt can cache downloaded modules locally to speed up repeated runs. Add a top-leveldownload_dir in your root terragrunt.hcl:
3. Prevent Accidental Destruction
Protect critical resources by adding aprevent_destroy lifecycle rule:
prevent_destroy setting.
If you need to remove the resource later, you must first remove or comment out the
prevent_destroy block.4. Use a Specific IAM Role
All Terragrunt operations should assume theKodeKloudTerragruntRole role. Retrieve your AWS account ID:
terragrunt.hcl:
5. Specify a Custom Terraform Binary & Version
Use the Terraform 1.82 binary packaged in this stack:6. Enforce a Terragrunt Version Constraint
Require Terragrunt in the>= 0.34.0, < 0.40.0 range:
7. Configure Retryable Errors
Handle transient network or locking issues by specifying retry patterns:Terragrunt Settings at a Glance
| Setting | Purpose | Example |
|---|---|---|
| terraform.source | Module source | "registry.terraform.io/.../vpc/aws" |
| download_dir | Cache directory for modules | "/path/to/.terragrunt_config" |
| lifecycle.prevent_destroy | Prevent critical-resource deletion | prevent_destroy = true |
| iam_role | Specifies assumed IAM role | "arn:aws:iam::123456789012:role/...TerragruntRole" |
| terraform_binary | Custom Terraform CLI path | "/path/to/terraform_1.82/terraform" |
| terraform_version_constraint | Lock Terraform to a specific version | "1.82" |
| terragrunt_version_constraint | Lock Terragrunt to a version range | ">= 0.34.0, <= 0.59" |
| retryable_errors | Patterns that trigger automatic retries | ["Error locking state:.*", "no such host"] |