Terraform is an infrastructure as code tool (IAC) that lets you build, change, and version cloud and on-prem resources safely and efficiently.
- Create and provision resources from any cloud provider (In our situation it would be AWS).
- Integrate with other modules, that have been already created and shared on github.
- Install Terraform
- AWS account (you might consider using Free Tier)
- Install AWS CLI for authentication with AWS config.
- From AWS account console, create a custom VPC and S3 bucket .
- Configure AWS CLI
aws configure
with access key, secret access key and region. - In provider.tf file :
- specify the
source
,region
andversion
for the cloud provider. - choose S3 bucket as the backend to store
terraform.tfstate
file.
- specify the
Each Module that was mentioned above has a certain role to achieve
- Reference the VPC, Create 2 private and 1 public subnets.
- Create internet Gateway.
- Create route table with its association between the public subnet and internet Gateway.
- Create a subnet group of the private subnets.
- Create a security group to allow HTTP/s traffic.
- Create EC2 instance (will be attached to the public subnet which was created in the Netwok module).
- Attach the security group to the EC2 instance.
- Create a security group to allow the access from the EC2's security group only.
- Create RDS instance (will be attached to the private subnet group which was created in the Netwok module).
- Attach the security group to the RDS instance.
main.tf
file contains the reference for each module(repo URL
andvariables
)output.tf
file in each module, allow passing values from a module to variables in another module
terraform init
intialize the project with all required modules and files of the cloud provider.terraform plan
validate all resources (dry-run technique).terraform apply
Create all resources (the real effect).