Provisioning AWS VPC With Terraform(HA)

Kubernetes Advocate
AVM Consulting Blog
3 min readJun 2, 2020
VPC with Terraform

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

  1. Installing terraform on ec2 instance and local system
  2. If Terraform is not installed you can download and install it from here.
  3. Installation of GitHub is must

2: We will provision VPC with help of terraform

  1. Creating AWS VPC with 10.0.0.0/16 CIDR block
  2. 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

  1. Provisioning InternetGateWay and map to AWS VPC.
  2. Provisioning both AWS VPC Route Tables (Private /Public )
  3. Provisioning VPC NAT Gateway in AWS
  4. 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.

replace the keys

Step -4: Build Amazon VPC Infrastructure:

  1. 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

vpc
subnets

👋 Join us today !!

️Follow us on LinkedIn, Twitter, Facebook, and Instagram

If this post was helpful, please click the clap 👏 button below a few times to show your support! ⬇

--

--

Kubernetes Advocate
AVM Consulting Blog

Vineet Sharma-Founder and CEO of Kubernetes Advocate Tech author, cloud-native architect, and startup advisor.https://in.linkedin.com/in/vineet-sharma-0164