This repository contains configurations for a RDS MySQL database, created according to Terraform best practices for both 'prod' and 'dev' environments. The DB is integrated with CloudWatch alarms to trigger alerts when CPU usage exceeds 80%.
- The database utilizes an existing VPC and creates its own security group and private subnets.
- AWS Secret Manager is used for storing and managing secrets securely.
- The project leverages modules and
.tfvars
files for configuring both 'prod' and 'dev' environments. - Inbound traffic to the database is configured on port 3306.
- Configuration includes automation for generating random database passwords.
- For state management, the configuration uses a remote S3 backend and locks the Terraform state in DynamoDB, but only for the 'prod' configuration.
- It's recommended to add 'secrets.tf' to the .gitignore file to protect sensitive information. This file is intended here solely for demonstration purposes.
- The setup uses a CloudWatch Alarm to trigger an alert when CPU usage exceeds 80% in the production environment.
.
├── README.md
├── alarm # CloudWatch Alarm module
│ ├── alarm.tf
│ └── variables.tf
├── mysql # RDS module
│ ├── mysql.tf
│ ├── secrets.tf
│ └── variables.tf
├── mysql-networking. # Networking module
│ ├── mysql-net.tf
│ ├── outputs.tf
│ └── variable.tf
└── root # Root module
├── dev # 'dev' environment
│ ├── dev.tfvars
│ ├── main.tf
│ ├── providers.tf
│ ├── terraform.tfstate
│ ├── terraform.tfstate.backup
│ └── variables.tf
└── prod # 'prod' environment
├── main.tf
├── prod.tfvars
├── providers.tf
└── variables.tf
DEV ACCOUT CONFIGURATIONS: | PROD ACCOUT CONFIGURATIONS:
Backup config section, enable backups. = OFF | ON Performance Insights enabled = OFF | OFF Multi-AZ. = OFF | ON Deletion protection = OFF | ON Final_snapshot = OFF | ON Copy tags to snapshot = OFF | ON Storage. Encryption. = OFF | ON IAM DB authentication = OFF | ON CloudWatch Logs = OFF | ON Storage autoscaling = ON | ON Create random passwd for db = ON | ON
Terraform Best Practices:
AWS RDS MySQL Best Practices:
Managing Secrets in Terraform:
These resources should provide comprehensive insights into Terraform best practices, optimizing AWS RDS MySQL deployments, and securely managing secrets in your Terraform configurations using AWS Secrets Manager.