In this lab, you’ll learn how to configure a remote state backend and set up the AWS provider using Terragrunt. We’ll generate Terraform configuration files automatically and initialize your stack to manage infrastructure in AWS. Before you begin, ensure you have AWS credentials configured: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.
1. Verify Your Terraform Version
First, confirm the Terraform CLI version installed on your system:2. Auto-Generate AWS Provider Files with Terragrunt
All Terragrunt configuration lives under your Terraform stack directory (terraform-stack/terragrunt.hcl). We’ll generate three files:
| Filename | Purpose | Key Settings |
|---|---|---|
providers.tf | Declares the AWS provider and region | region = "us-east-1" |
versions.tf | Pins the AWS provider version | version = "~> 5.0" |
backend.tf | Configures remote state with an S3 backend | bucket, key, region, lock |
2.1 Generate providers.tf
Add this block to terragrunt.hcl to configure AWS in us-east-1:
2.2 Generate versions.tf
Next, pin to the latest major AWS provider release:
Ensure your
terragrunt.hcl includes these generate blocks before initializing.3. Initialize Terragrunt
Switch into your Terraform stack directory and run initialization:providers.tf and versions.tf created automatically.
4. Configure Remote State in S3
An S3 bucket namedkk-infra-state-<random> already exists for your Terraform state. Discover its exact name:
terragrunt.hcl with this block to generate backend.tf:
Never commit your AWS access keys or state files to version control.