How To Automate AWS Cloud Using Terraform
Posted By : Ankit Gupta | 27-Aug-2020
In this blog post, you'll learn how to automate AWS cloud using Terraform.
To create a complete infrastructure of hosting a web page on AWS Cloud using Terraform, follow the steps below :
STEP1 : First creating a key-pair and storing it in our local machine. This key will be used to login into our EC2 machine.
STEP2 : Creating a security group which allows Port No 80 (for HTTP) and Port No 22 (for SSH).
STEP3 : Then, launching an EC2 instance with the key-pair and security group created in above steps.
STEP4 : We will now configure our O.S. so that it can be used to host a web page — Install Apache Web Server and start the required services.
STEP 5: Now, we will create an EBS volume and attach it to our instance.
STEP 6: Mount the volume into default directory of web server. The whole process of formatting and mounting the volume will be done using Terraform.
STEP 7: Now, we will clone the Github repo containing the webpage, to our volume’s directory.
STEP 8: We will then create a S3 bucket which will store the images for our web page.
STEP 9: Finally, we will create a CloudFront distribution for faster delivery of the image. At last, the CloudFront URL will be appended into our web page.
So now let’s begin!
NOTE : For performing this practical, you should have Terraform installed in your local machine.
provider "aws" { variable ami_id { variable instance_name { variable server-sg_name { variable bucket_name { variable key_name { variable object_name { resource "tls_private_key" "key-pair" { resource "local_file" "private-key" { resource "aws_key_pair" "key-pair-tf1" { resource "aws_security_group" "server-sg" { resource "aws_instance" "server" { resource "aws_ebs_volume" "pendrive" { tags = { resource "aws_volume_attachment" "pd_attach" { resource "null_resource" "attach-pd" { resource "aws_s3_bucket" "picture1997-bucket" { resource "aws_s3_bucket_object" "picture-upload" { locals { resource "aws_cloudfront_distribution" "cloudfront" { forwarded_values { cookies { output "Instance-Public-IP" { |
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ankit Gupta
Ankit is a Redhat Certified System Administrator and Redhat Certified Engineer. He is interested in learning new DevOps tools . He likes Linux, DevOps , Automation & Cloud Computing. He always try to complete the assigned tasks within in the given time.