![]() |
Terraform is an IAAC tool used to automate programmatic infrastructure provisioning. Here in this guide, I will first discuss what is AWS VPC. Then I will discuss terraform. After this, I will walk you through the different steps to write a code using Terraform to create a custom AWS VPC using subnet, internet gateway, and routing tables. Table of Content What is AWS VPC?AWS VPC is a service that helps users create a virtual network on the AWS cloud platform. In the VPC, users can create their own public or private subnets, routing tables, internet gateways, and NAT gateways. Users can create a security group associated with a VPC for better security, here users define inbound and outbound rules. NACLs are used at the subnet level to allow or deny particular IPs when trying to access the subnet. AWS VPC gives users complete control over the virtual network on the AWS cloud platform. Overall we can say that this level of control enables users to create a custom virtual network to build a secure and scalable architecture for applications. What is Terraform?Terraform is an Infrastructure as Code(IAAC) tool that is used to define and provision infrastructure using a declarative configurational language called HashiCorp Configuration language(HCL). It has a simple syntax that helps to provision infrastructure in multiple cloud platforms. Using terraform increases the speed and reliability. It helps organizations to automate programmatically their infrastructure provisioning. Terraform’s version control feature enables teams in an organization to manage infrastructure configurations as code, facilitating collaboration and also ensuring the tracing of changes over time. Its simplicity, cross-platform compatibility, and automation capabilities make it an essential tool for an organization to maintain control, reliability, and scalability. How To Create AWS VPC Using Terraform?: A Step-By-Step GuideThe following are the steps that guides you on how to create AWS VPC using Terraform: Step 1: First mention the provider and region in which you want to create VPC. provider.tf provider "aws" { Step 2 : Create a VPC . Here mention the CIDR block and give a name to the VPC . create_vpc.tf resource "aws_vpc" "main" { Step 3 : Then create a subnet inside the VPC with the following subnet.tf file: resource "aws_subnet" "main" { Step 4 : But the subnet is isolated now . If you create an EC2 instance inside this subnet then you can not connect the EC2 instance as it is present in an isolated environment . So you need an internet gateway . internet_gateway.tf resource "aws_internet_gateway" "igw" { Step 5 : Create a route table and associate the route table with subnet . Here in the route all the traffic is passed through internet gateway . route_table.tf resource "aws_route_table" "rt" { route_subnet_association.tf resource "aws_route_table_association" "a" { Step 6 : After this execute all these terraform files using the below commands one by one . terraform init Step 7: Check on your AWS console whether the VPC is created or not
terraform destroy
Best Practices of using Terraform for AWS VPCThe following are the best practices of using Terraform:
Trouble shooting issues of TerraformThe following are the trouble shooting issues of Terraform:
ConclusionHere first we learned basics about AWS VPC and terraform . Then followed the steps to create an AWS VPC . Here inside the VPC we have created a public subnet , an internet gateway which helps the traffic to go in and out of the subnet and finally created a route table and associated with the subnet. AWS VPC Using Terraform – FAQsWhat is a subnet in VPC ?
What are NAT gateways used for ?
How public subnet is different from private subnet ?
How to ensure that EC2 instance inside the VPC gets internet connectivity ?
What is the use of route table in VPC ?
|
Reffered: https://www.geeksforgeeks.org
Dev Scripter |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |