Build Complete AWS Infrastructure with Terraform!

Sri Sravya
4 min readJun 16, 2020

Setup your Website infrastructure in one-Click…..

AWS with Terraform

In this article,i am going to demonstrate the Deployment of WebSite using Terraform on AWS cloud in a single go!

To know more in detail about Terraform,What terraform is,It’s importance and it’s use-cases,Please go through the below link.

Task:

-Have to create/launch Application using Terraform;

1. Create the key and security group which allow the port 80.

2. Launch EC2 instance.

3. In this Ec2 instance use the key and security group which we have created in step 1.

4. Launch one Volume (EBS) and mount that volume into /var/www/html

5. Developer have uploded the code into github repo also the repo has some images.

6. Copy the github repo code into /var/www/html

7. Create S3 bucket, and copy/deploy the images from github repo into the s3 bucket and change the permission to public readable.

8. Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html

Prerequisite:

1.SOFTWARES Installation:

  • >Terraform
  • >AWS Account
  • >AWS CLI-V2

https://awscli.amazonaws.com/AWSCLIV2.msi

2.SETUP THE PATH:

terraform-path-setup-process
aws-cli-path-variable

Diving into the task now:

Step-1:Configure aws profile using the command:

$aws configure — profile profilename

[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[user1]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY

[default]
region=us-west-2
output=json

[profile user1]
region=us-east-1
output=text

Step2: Create the key and security group which allow the port 80.

Step-3: Launch EC2 instance, use the key and security group created in before step.

Step-4,5&6:

Launch one Volume (EBS) and mount that volume into /var/www/html.

Developer have uploded the code into github repo also the repo has some images.

Copy the github repo code into /var/www/html.

Step-7:Create S3 bucket, and copy/deploy the images from github repo into the s3 bucket and change the permission to public readable.

Step-8:Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html.

Execution:

> terraform init

> terraform apply -auto-approve

To destroy entire infrastructure:

>terraform destroy

Output Screens:

terraform init
instances launced automatically
image used:marvel
output screen
destroyed setup
files and keys created.

GitHub Link:

Thankyou for Reading :)

Happy Learning!

--

--