Terraform project with best practice, meta-arguments, terraform remote state, data blocks and etc.
final-project/
│
├── modules/
│ ├── networking/
│ │ ├── README.md
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ ├── autoscaling/
│ │ ├── README.md
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
├── environments/
│ ├── prod/
│ │ ├── providers.tf
│ │ ├── main.tf
│ │ ├── data.tf
│ │ └── outputs.tf
│ │
│ └── dev/
│ │ ├── providers.tf
│ │ ├── main.tf
│ │ ├── data.tf
│ │ └── outputs.tf
│
├── .gitignore
└── README.md
.gitignore
: ignores big and medium files and folders created by Terraform.
networking/
: The networking module for VPC, Public and Private Subnets, CIDR blocks, IGW, NAT, EIP, Route Tables and Associations.autoscaling/
: The autoscaling module for Launch Template, User Data, Security Groups and Supplementary Security Group, ALB, Target Group, Listener, Autoscaling Group.
Each module contains:
main.tf
: Configuration for that specific module.variables.tf
: Module-specific variables.outputs.tf
: Output values specific to that module.README.md
: Brief description to that module.
prod/
: Environment-specific configurations for production. S3 bucket and static website.dev/
: Environment-specific configurations for development. Networking and Autoscaling modules are used.
Each environment includes:
main.tf
: Configuration specific to that environment.variables.tf
: Environment-specific variables.outputs.tf
: Environment-specific outputs.providers.tf
: Provider-specific outputs.
- VPC
- Public Subnets
- Private Subnets
- Internet Gateway
- NAT Gateway
- Elastic IP for NAT
- Private and Public Route Tables
- Launch Template
- Autoscaling Group
- Application Load Balancer
- Target Group
- Listener
- and etc.
export AWS_ACCESS_KEY_ID=<write your access key id>
export AWS_SECRET_ACCESS_KEY=<write you secret access key>
export AWS_DEFAULT_REGION=<write default region to create resource in>
Then perform the following commands on the root folder:
terraform init
terraform initializationterraform plan
to see the infrastructure planterraform apply
to apply infrastructure buildterraform destroy
to destroy the infrastructure
Name | Version |
---|---|
terraform | >= 1.1.0 |
aws | >= 3.71.0 |
Name | Version |
---|---|
aws | >= 3.71.0 |