Tuesday, March 7, 2023

How to deploy Webapp on AWS using Terraform


Terraform is an open-source infrastructure as a code software tool created by HashiCorp. Users define and provide data centre infrastructure using a declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON.

Amazon Web Services(AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet.

In this blog, we are going to deploy a web app on the top of AWS using Terraform.

To connect with AWS we need to write a code in HCL(HashiCorp Configuration Language)


we can use the provider keyword to connect with any of the cloud providers or any other tools like k8s, GCP etc, region we need to specify the region in which we need to create resources and the last profile contains the credentials of the AWS account which we are using to create resources.

Now, we need to create the private key to create an instance and at last, we use the same private key to configure the instance using terraform



We have a private key also now let's create an EC2 instance

Now, we need to create an EBS volume and attach it to EC2 instance which we have created so that our data will be persistent

Let’s configure our web app using terraform only we can use ansible for configure part but for now, am doing the same using terraform only

First, we need to install the providers for that we need to use the command “terraform init”



We are ready with terraform code, now for to check the syntax of the code we can use terraform validate command and to know the changes by code we use terraform plan command which will show all the things which terraform going to create



It show code that we are using is going to create 5 resources and to run this code we need to use the command “terraform apply”



At last, we need to enter yes to apply the changes


Code successfully run and did all the provisioning as well as configuring tasks on AWS




We are able to see our web page which we have deployed using terraform on AWS.

With the help of terraform with one click, we can deploy our whole application on the top of AWS.

Thank You for Reading !!! I hope you find it helpful.









No comments:

Post a Comment