How to Setup Instance in AWS Using Terraform :

unrecognizable hacker with smartphone typing on laptop at desk
Reading Time: 3 minutes
How To Create AWS Ec2 Instance Using Terraform | Terraform Ec2 Module

Hello Readers, I hope you all are doing so well. In this blog we will see that how we can set-up Instance in AWS using terraform. Before starting you must have Terraform, AWS CLI install on your machine and they both must be configure. So stay tuned with me.


It is easy to set-up Instance using terraform. In order to do so you should follow certain steps.

These are as follows:

STEP 1: Go the given and copy the content from the terraform docs of aws_instance.

STEP 2: Now; Open your terminal and make one directory and under that directory make file named as, and paste the content that you have copied from the URL.

Run the following commands to do so :

cd Documents
mkdir Terraform
mkdir Instance

STEP 3: Check your file by :

This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-12-52-51.png

STEP 4: Remember you should have aws CLI in your local machine and then Configure your AWS by running the command:

aws configure

STEP 5: Make one more file named as to give your credentials for AWS as:

provider "aws"{
region = "us-east-1"
access_key = "Your_Access_Key"
secret_key = "Your_Secret_Key"

STEP 6: Now run the following command :

terraform init
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-13-02-21.png

STEP 7: Now let’s plan it . Plan is basically you are creating anything and what exactly you will get as the result.

terraform plan
This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-13-09-46.png

STEP 8: finally run the command given below to apply it. You will see your s3 bucket is 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

STEP 9: Login into your AWS Console and search for service as Instance, you will see your Instance is created.

This image has an empty alt attribute; its file name is Screenshot-from-2022-02-16-13-15-09.png

So , Yes we have successfully created our Instance using terraform in AWS.

Conclusion :

So, In this blog we have seen in some simple steps how we can create instance in AWS using terraform. Thanks for being with me till the end. If you find this blog helpful do share with your friends.


Reference :

Written by 

Mayuri Dhote is a Software Consultant at Knoldus Software. She has completed her MCA from VIT University. She has very dedicated towards her work. She has always ready to learn new things. Her practice area is Devops. When not working, you will find her writing poems and poetry.