Step-by-Step Process
1. Navigate to the Correct Directory
Move into the appropriate environment directory: For development:2. Initialize Terraform
- Initialize Terraform
- Download the
inputs.hclfiles from S3 with your existing configurations, or create a new one.
3. Configure Your Application
Edit theinuts.hcl file and add your service definition under the microservice section.
Configuration Fields Explained
| Field | Description | Example Value |
|---|---|---|
name | Unique application name | "your-app-name" |
tier | Application tier (usually "application") | "application" |
namespace | Environment namespace | "development" or "production" |
ecr | ECR (Elastic Container Registry) settings | {} (empty for default) |
deployer.oidc.subjects | GitHub repository + branch patterns | "repo:your-org/your-app:ref:refs/heads/branch-name" |
static_secret.create | Create environment variables secret? | true |
clusters | Per-cluster configuration | Defines secrets and IAM policies |
Pipeline Role
IAM role for your CI/CD pipeline to deploy the application
Application Role
IAM role for your app to access AWS services
Application Secret
AWS Secrets Manager secret for environment variables
ECR Repository
Container registry for storing Docker images
4. Plan and Apply Changes
Run the following commands to review and apply changes:The
TG_SECRET=save flag ensures your local configuration is persisted to AWS.5. Save the Output Values
After Terraform applies successfully, capture the output values:Example Output
A typical output looks like this:Understanding the Output Values
| Value | Description | Purpose |
|---|---|---|
service_account_role_arn | Role used by Kubernetes service account | Application permissions in cluster |
ecr_repository | Container registry URL | Stores Docker images for the app |
pipeline_role | CI/CD deployment role | Used by GitHub Actions |
static_secret | ARN of environment secret | Holds app configuration variables |
Configure Application Secrets
At this stage you can add your environment variables:- Open AWS Secrets Manager in the AWS Console
- Find the secret created for your app
- Add key-value pairs for environment variables
Next Steps
With AWS resources created and outputs saved, move on to Create Manifest Files to configure your Kubernetes deployment.Troubleshooting
Permission Denied Error
Permission Denied Error
Ensure you’re using AWS credentials with the right permissions for the workload account.
Terraform State Lock Error
Terraform State Lock Error
State lock issues
Terragrunt and Terraform use DynamoDB locks to prevent multiple people from applying changes at the same time on the same unit. If you see a state lock error, it usually means someone else is already running a deployment.What to do:- ⏳ Wait for the other deployment to finish.
- ✅ Verify you’re not overwriting someone else’s changes.
- ✅ Refresh your parameter. Save your current changes locally (they may be overwritten).
- 🚀 Apply your changes once you’re sure everything is okay.
Configuration Not Found
Configuration Not Found
Double-check you are in the correct directory and have successfully run
tg init.