This project establishes a comprehensive infrastructure using Terragrunt to manage reusable Terraform modules across two environments: dev and prod. The setup includes deploying critical AWS resources and services to ensure high availability, scalability, and monitoring.
- EKS Clusters: Kubernetes clusters for container orchestration and management.
- RDS Instances: Managed relational databases tailored for each environment.
- VPCs & Subnets: Custom Virtual Private Clouds with public and private subnets for network isolation.
- Security Groups: Network security configurations for controlling traffic.
- Monitoring Stack: Integration of Prometheus, Alert Manager, and Grafana for observability, alerting, and monitoring.
- ArgoCD: Continuous Delivery solution for automated Kubernetes deployments in both environments.
environments/
: Contains the environment-specific Terragrunt configurations for dev and prod environments.dev/
: Contains theterragrunt.hcl
file for the dev environment.prod/
: Contains theterragrunt.hcl
file for the prod environment.
modules/
: Contains the reusable Terraform modules for resources such as EC2 instances, VPC, and S3.ec2.tf
: EC2 instance configuration.s3.tf
: S3 bucket configuration.vpc.tf
: VPC configuration.provider.tf
: AWS provider configuration.variables.tf
: Input variables used across modules.
- Terraform installed.
- Terragrunt installed.
- AWS CLI configured with proper access to the required accounts and regions.
To deploy the infrastructure for both dev and prod environments, navigate to the environments
directory and run the following commands:
cd environment
terragrunt run-all init --reconfigure
This command initializes the backend configuration for all modules in both the dev and prod environments.
terragrunt run-all init --upgrade
This command upgrades the Terraform providers and modules to the latest versions in both environments.
terragrunt run-all plan
This command generates an execution plan for both the dev and prod environments, showing what changes will be made to your infrastructure.
terragrunt run-all apply
This command applies the infrastructure changes in both environments, provisioning the necessary resources such as EC2 instances, S3 buckets, and VPCs.
To switch between the dev and prod EKS clusters, run the following commands:
-
For dev cluster:
aws eks update-kubeconfig --name cluster-1-dev --region eu-central-1
-
Using k9s
-
For prod cluster:
aws eks update-kubeconfig --name cluster-1-prod --region eu-central-1
-
Using k9s
These commands update your kubeconfig file, allowing you to interact with the desired Kubernetes cluster.
To connect to your dev or prod RDS clusters, follow these steps:
-
Find the RDS Endpoint:
- You can find the RDS endpoint in the AWS Management Console by navigating to:
- RDS > Databases > [Your RDS Cluster] > Connectivity & Security.
- Alternatively, it will be shown in the Terraform outputs, you can retrieve it directly from the output variables.
- You can find the RDS endpoint in the AWS Management Console by navigating to:
-
Retrieve RDS Username and Password from Secrets Manager:
- The RDS credentials (username and password) are stored in AWS Secrets Manager.
- Go to AWS Secrets Manager and look for the secret named something like
dev-rds-credentials
orprod-rds-credentials
(depending on your environment). - Inside the secret, you’ll find the RDS username and password for your connection.
-
Connect to the RDS Instance Using MySQL:
-
For dev environment:
mysql -h dev-rds-cluster.cluster-cxzadf8nmshb.eu-central-1.rds.amazonaws.com -u <username-from-secret-manager> -P 3306 -p
(Replace
<username-from-secret-manager>
with the actual username retrieved from Secrets Manager. You will be prompted to enter the password.) -
For prod environment:
mysql -h prod-rds-cluster.cluster-cxzadf8nmshb.eu-central-1.rds.amazonaws.com -u <username-from-secret-manager> -P 3306 -p
(Replace
<username-from-secret-manager>
with the actual username retrieved from Secrets Manager. You will be prompted to enter the password.)
-
To destroy the infrastructure for both dev and prod environments, you can use the following commands.
terragrunt run-all destroy
- Each environment (dev/prod) has its own
terragrunt.hcl
file, which points to the shared Terraform modules located in themodules/
directory. - Changes applied will be specific to the environment (either dev or prod), but running
terragrunt run-all
ensures that both environments are handled simultaneously.