Provisioning AWS VPC With Terraform(HA)
Here we will learn to provision HA VPC in AWS with multiple subnets in different AZs
Terraform: Its an open tool which helps to Provision infrastructure in Cloud
1: Pre-Requisites to provision VPC with help of TF :
We will be requiring Amazon Access and secret key
- Installing terraform on ec2 instance and local system
- If Terraform is not installed you can download and install it from here.
- Installation of GitHub is must
2: We will provision VPC with help of terraform
- Creating AWS VPC with 10.0.0.0/16 CIDR block
- We will create Multiple subnets (Public/Private)
Public subnets will cover web and app servers = Accessible via Internet
Private subnets will cover Database servers = Not Accessible
Lets start the lab
- Provisioning InternetGateWay and map to AWS VPC.
- Provisioning both AWS VPC Route Tables (Private /Public )
- Provisioning VPC NAT Gateway in AWS
- Associating VPC Subnets to routing tables.
3: Provisioning AWS VPC:
Here we will provision VPC with help of terraform script provided on Git
To get the Terraform script, clone repository provided below.
It consist of the complete code to Provison Amazon VPC.
Use the below command to get code for same :
git clone https://github.com/vineet67sharma/AWS-Terraform
The Repo have all those files as mentioned below :
vpc-variable.tf:
This file have all the global variables to provision VPC
Example Access keys , secret keys , Region , Availability zones
We can also change the values as per requirement .
vpc-main.tf
This file contains the entire code required to provision the highly available Amazon VPC.
aws.tf
This file provides configuration file.
terraform.tfvars
The file is the default name for the variable input file .
Terraform will get the input values from Tfvars file. We need to add or remove the Amazon API Keys in the tfvars file.
Step -4: Build Amazon VPC Infrastructure:
- This is the first command that should be run after writing a new Terraform configuration.
$terraform init
2. The plan command is used to initiate an execution plan. It will show you the resources with provisions.
$ terraform plan
3. The apply command is used to apply the changes required to reach the desired state of the configuration.
#terraform apply -var-file terraform.tfvars
👋 Join us today !!
If this post was helpful, please click the clap 👏 button below a few times to show your support! ⬇