How to Setup Networks in AWS using Terraform

close up of computer screen
Reading Time: 3 minutes
This image has an empty alt attribute; its file name is hqdefault.jpg

Hello Readers, In this blog we’ll see that how we can set-up OR create networks in AWS using Terraform. Before starting you must have Terraform, AWS CLI install on your local machine and they both must be configure. 

SO LET’S GET START!

It is easy to set-up Networks using terraform. In order to do so you should follow certain steps. These are as follows:

  • Go the terraform docs and copy the content from the terraform docs of aws_vpc, aws_subnets, aws_route_table.
  • Open your terminal and make one directory and and under that dir make file named as networks.tf , and paste the content that you have copied from the url.

Run the following commands to do so :

cd Documents
mkdir Terraform
mkdir aws
nano networks.tf
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-12-48-56.png
  • Check your file by :
cat networks.tf
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-12-52-51.png
  • Remember you should have aws CLI in your local machine and then Configure your AWS by running the command:
aws configure
  • Make one more file named as provider.tf to give your credentials for AWS as:
provider "aws"{
region = "us-east-1"
access_key = "Your_Access_Key"
secret_key = "Your_Secret_Key"
}

  • Now you can run the command in your terminal as given below:
terraform init
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-13-02-21.png
  • Now let’s plan it . Plan is basically you are creating anything and what exactly you will get as the result when you run the given command.
terraform plan
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-13-09-46.png
  • finally run the command given below to apply it. You will see your netwroks are creating after providing it the value as ‘Yes’.
terraform apply
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-13-13-36.png
  • Login into your AWS Console and search for service as VPC, you will see that your vpc, subnets, internet gateway and route table is created.

So now we have successfully created our networks using terraform in AWS.

Happy Learning!

Conclusion

So, In this blog we have seen in some simple steps how we can create and setup vpc, subnets, internet gateway and route table in AWS using terraform.Thanks for being with me till the end. If you find this blog helpful do share with your friends.

Reference

Click here

knoldus

Written by 

Ashi Dubey is a Software Intern at Knoldus Inc Software. She has a keen interest toward learning new technologies. Her practice area is Devops. When not working, you will find her with a Book.