Glody Mateta
3 min readOct 23, 2020

--

Provisioning Your AWS VPC With Terraform

VPC Subnet wit Terraform

Hello World, today we will go through a few steps on how to provision a High Availability (HA) Virtual Private Cloud (VPC) in AWS that has multiple subnets in different Availability Zones (AZ).

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 public subnets will cover Database servers = Not Accessible

Let’s 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 consists of the complete code to provision Amazon VPC.

Use the below command to get code for same :

https://github.com/vineet67sharma/AWS-Terraform

The Repository 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 files.

terraform.tfvars

Terraform will get the input values from tfvars file. We need to add or remove the Amazon API keys in the tfvars files.

4: Build Amazon VPC Infrastructure:

Note: make sure you’ve saved the code within your text editor before we run the first command in Terraform.

  1. The first command that should be run after writing a new Terraform configuration is (terraform init)

2. The second command (terraform plan) will initiate an execution plan. It will display all of the resources with provisions.

3. Finally, the apply command is used to apply the changes required to reach the desired state of configuration. (terraform apply -var-file terraform.tfvars)

--

--