Using Terraform with AWS

Using Terraform with AWS  Ashish Pandey
Posted on Aug. 7, 2020, 10:18 a.m.

Terraform with AWS - Banner Image


What is Terraform?

Terraform is an open-source software made by Hashicorp Inc and the open-source community. It is an Infrastructure-provisioning tool that uses a high-level language. The language which it uses is known as Hashicorp Configuration Language (HCL).  Terraform can be used to manage most of the commonly known infrastructure providers such as public cloud, private cloud, and other modern tools such as Github, Docker, and Kubernetes. 


What is an Amazon Web Service (AWS)?

AWS is a part of Amazon and the leading cloud computing platform in the industry. AWS Cloud provides hundreds of services that are referred to as resources in Terraform. In turn, it means that these hundreds of services can be created, managed, and destroyed by using Terraform. 

To know in detail how to configure Terraform, we recommend reading How to do cloud automation using Terraform?


If you don't want to go into the details the steps to use Terraform to provision AWS can be summarised in the points given below - 



  1.  You need to have an AWS account.
  2. Create an IAM user with programmatic access. (Get the access key and secret access key)
  3. Have a system that can access the AWS cloud.
  4. Install AWS CLI on your system



So, these are the steps that you need to follow to make your first ec2 instance on AWS using Terraform:

  1. Download Terraform and install the exact version of Terraform which is for your system software.
  2. Configure AWS CLI with AWS access key, AWS secret access key, and the default region.
  3. Then you need to make a new file with the .tf extension. The name does not matter but usually, it is referred to as 
  4. In you can explicitly state that we are using the AWS provider plugin from Terraform, and also provide the credentials (though not recommended) and default region, etc.
  5. We will then use the resource identifier such as “aws_instance” to state that we are trying to provision an EC2 instance followed by a user-defined name of the resources. You can rename it to anything. 
  6. We then have to supply the configuration of the resource such as an AMI type, instance type,disk-storage, etc for an ec2 instance. 
  7. Run the Terraform init command where you have created the file to download and initialize the appropriate provider plugins. In this case, we will be downloading the AWS provider plugin that we had specified in our file.
  8. Once you have completed the init command, you need to execute the terraform plan command, which will help you see what your infrastructure will do to the application before it is actually put into it. This is a very useful command for the developers, as it will help you find out if any changes are required to the infrastructure before it will be used in the application. 
  9. And then you need to create the instance with the help of the terraform apply command. This command helps you to apply all the changes that you made to your infrastructure to the application. 
  10. Terraform will ask for confirmation before actually providing resources on the cloud, though this behavior can be modified to make it more automated.

Now, if you go to your EC2 section on the AWS console you can see that an instance with provided configuration would have been created successfully. 


If you are looking to deepen your understanding in Terraforma and AWS, do check out the training in Terraform and AWS offered by zekeLabs.

Ashish Graduated from MNNIT Allahabad in the Computer Science stream. With ~10 years of Corporate experience in companies like Aricent in the telecom domain & Guavus in the big data domain, Ashish brings a lot of insight into Tech Industry Space. Here goes his expertise: Cloud Technologies - AWS, Azure, Docker, Kubernetes, Terraform, DevOps Tools - Chef, Puppet, Ansible, Jenkins, Programming - Python, C, Java. He worked with Nokia Siemens Network regarding Infrastructure Management. Apart from Tech. industry, he is passionate about the social sector.

Keywords : terraform aws Technology

Recommended Reading

Using Terraform with Azure

Terraform is open-source software built by Hashicorp along with the community. The objective is to provide automation for any API-based tools. Since all the cloud service providers expose an API, So Terraform can be used to automate and manage hybrid-cloud ...

How to do Cloud Automation using Terraform?

Cloud Automation is coming together of Cloud Computing with Infrastructure Automation. As cloud adoption is accelerated in the industry, the industry needs to automate the management of cloud infrastructure and cloud services. All of the public cloud servic...

Know more about Terraform

Terraform is a tool made by Hashicorp. It is also used as a tool for cloud-automation. It is an open-source software to implement “Infrastructure as Code (IaC)”. The language used to write the terraform script is known as Hashicorp Configuration Language (H...

How to install Kubernetes Clusters Using Terraform?

Kubernetes is a container orchestration platform that can be used to deploy and manage a containerized applications. Generally, Microservices-based applications are first converted into Docker (or other container runtimes) images and then these microservice...