Skip to main content
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:
You can run commands in VS Code’s integrated terminal via your browser for easy copy & paste.

1. Verify Your Terraform Version

First, confirm the Terraform CLI version installed on your system:
You should see output similar to:

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:

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:
On success, you should see providers.tf and versions.tf created automatically.

4. Configure Remote State in S3

An S3 bucket named kk-infra-state-<random> already exists for your Terraform state. Discover its exact name:
Copy the bucket name and update your root terragrunt.hcl with this block to generate backend.tf:
Never commit your AWS access keys or state files to version control.

5. Reinitialize & Apply Your Stack

Apply the new backend settings and spin up resources:
You should see Terraform planning and applying an AWS VPC. Verify the VPC and related resources in the AWS Console once complete.

6. Reconfigure Remote State (Optional)

To update or reconfigure the backend at any time:

Watch Video

Practice Lab