Secure Terraform Directory Structure
Secure Terraform Directory Structure
(31/07/2024 )
Example Terraform Directory Structure
├── modules
│ ├── vpc
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── ec2
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── rds
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ └── s3
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
├── environments
│ ├── dev
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── terraform.tfvars
│ ├── prod
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ └── terraform.tfvars
│ └── staging
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── terraform.tfvars
├── scripts
│ └── init-backend.sh
├── .gitignore
├── backend.tf
├── main.tf
├── outputs.tf
├── providers.tf
├── terraform.tfvars
└── variables.tf
2. Environment Separation:
Maintain separate directories for different
environments (dev, prod, staging). This allows for
isolated configurations and reduces the risk of
accidental changes to the production environment.
5. Version Control:
variable "db_password" {
description = "The password for the RDS instance"
type = string
sensitive = true
}
```
```
data "aws_secretsmanager_secret_version"
"db_password" {
secret_id = "arn:aws:secretsmanager:us-west-
2:123456789012:secret:mysecret"
}
variable "db_password" {
.terraform/
Secrets directory (if any)
secrets/