Technology News

Building a VPC ( Virtual Private Cloud ) in AWS using Terraform

5 min read

In this article, we are going to explain how to “Building a VPC ( Virtual Private Cloud ) in AWS using Terraform”.

 

What is a VPC ( Virtual Private Cloud )?

 

Amazon VPC(Virtual Private Cloud)  enables you to launch AWS resources into a virtual network that you’ve defined(logically isolated section of AWS).

 

Instead of using the GUI(amazon console), we will learn to provision resources using scripts.

 

The main components of VPC ( Virtual Private Cloud ) are – Internet gateway, VPC, Route Table, NACL, Security groups, Subnets, jump host, and Instance.

 

 

 

We will deploy some of these resources with the help of a script without using the GUI and the AWS console.

 

What are the advantages and disadvantages of using a VPC ( Virtual Private Cloud )?

 

The advantages of a VPC are which you’re able to functionally use your own private cloud the usage of at ease provider and you’ll have got right of entry to all capabilities and functions of the general public cloud computing issuer website hosting your VPC ( Virtual Private Cloud ).

 

There also are a few disadvantages also. First is the price. Of direction, it depends on your public cloud issuer or MSP, but in all instances, a VPC expenses more to perform than popular cloud hosting. In a few instances, it’s miles extra highly-priced than operating a personal cloud on-premises.

You need to bear in mind ingress and egress charges of facts shifting in and out of the VPC(Virtual Private Cloud), plus the fee of a non-public connection according to an hour. There are different extras that you could pick as properly, and it won’t be long until the price of a VPC crossed your limit. 

Latency can be trouble for people who use VPCs over the open net the use of a personal connection. Of path, this depends on in which you are using the VPC in terms of the bodily factor of presence, how chatty the utility is, and the kind of VPN encryption.

 

 

Here are the steps to Building a VPC ( Virtual Private Cloud ) in AWS using Terraform:

 

1.Building a Virtual Private cloud and adding an Internet gateway.

 

 

When you create a VPC, you must specify an IPv4 CIDR block for the VPC. The allowed block size is between a /16 netmask (65,536 IP addresses) and /28 netmask (16 IP addresses).

 

An Internet Gateway is a logical connection between an Amazon VPC and the Internet.

 

2. Building route table.

 

 

A routing table contains a set of rules, called routes, that are used to determine where network traffic from your subnet or gateway is directed. We are building a web-server hence the cidr_block = “0.0.0.0/0” which allows all traffic from the internet.

 

3.Building subnet and associating subnet with a routing table.

 

 

Associates a subnet with a routing table. The subnet and route table must be in the same VPC. This association causes traffic originating from the subnet to be routed according to the routes in the routing table. 

 

4. Creating a security group.

 

 

A security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic. Inbound rules control the incoming traffic to your instance, and outbound rules control the outgoing traffic from your instance. In this script, we have allowed traffic from HTTP(80), HTTPS(443), and SSH(22).

 

 

5. building a network interface, assigning an elastic IP, and provisioning the Ubuntu server.

 

 

An Elastic IP address is a public IPv4 address, which is reachable from the internet. If your instance does not have a public IPv4 address, you can associate an Elastic IP address with your instance to enable communication with the internet.

 

Finally provisioning the Instance, we are using Ubuntu AMI and t2 micro instance.

 

Now the script is complete and ready to be tested.

 

First, we have to initialize terraform with terraform init command:

 

 

Now we can run our script with the terraform apply command.

 

 

Now we can log in to the console to check whether the resources are deployed or not.

 

 

 

Our VPC(Virtual Private Cloud) resources are successfully deployed using Terraform.

 

What are the Benefits of a VPC ( Virtual Private Cloud )?

 

  • Protection: facts passed thru a VPC stays inside a patron’s manipulate without crossing the net. in addition, with all customers operating on the same again-give up infrastructure, VPC companies have a fairly-vested hobby in maintaining matters walking smoothly and securely, whilst keeping high stages of uptime. To preserve customers’ happiness, professional VPC carriers normally spend a whole lot extra time than any individual could gain this stage of reliability and protection.

 

  • Costs: because VPCs are inside a public cloud, clients nevertheless gain from economies of scale, sharing charges with different groups without compromising the aforementioned protection.

 

  • Quick integration and deployment: A VPC can be integrated with other VPCs, the general public cloud, or on-premise infrastructure. as soon as in the region, it successfully becomes a hybrid cloud, which through definition, is a couple of cloud working in synchronization.

 

  • Seamless upgrades: With all customers running on identical hardware, the VPC company can improve all of us incrementally and without downtime; maximum providers will refresh the underlying hardware while continuously acquiring faster and higher hardware. over time, clients’ workloads sincerely get extra at ease and quicker.

 

Thank you for reading. We hope this gives you a good understanding. Explore our Technology News blogs for more news related to the Technology front. AdvanceDataScience.Com has the latest in what matters in technology daily.

Tagged , , , , , , , , ,