AWS Infrastructure Automation By Terraform: Configure WebServer With files in EFS

I always had this thought what if I can automate the infrastructure? as a CS engineer always try to make automate all the processes. Always and I love to work with AWS as my primary cloud service provider using AWS with Terraform. For Continuous Integration, I cant always log in to the AWS console and provisioning the servers. So I made an Infrastructure as code using Terraform.

What is Terraform?

The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.

My Aim for This Project :

Context

  1. Launch an Instance In EC2 and install Required Software in it. i.e. httpd, git, PHP, amazon-efs-utils.
  2. Create an EFS Storage as Backup and Mount it to /var/www/html
  3. Create an S3 Bucket and store the Images
  4. Make a CloudFront URL for that Images

Lets Go:-

Here I Have Create a Security Group which allow Http and ssh as inbound and all services as outboung

Create an EFS Storage as Backup and Mount it to /var/www/html

Here I have Create a EFS Storage And mounted it to The Secuity Grp and Subnet.

Launch an Instance In EC2 and install Required Software in it. i.e. httpd, git, PHP, amazon-efs-utils.

This Will Launch and instance with the same subnet as EFS. and Will be Preconfigured with WebServer and Mounted with EFS.

Create an S3 Bucket and store the Images

The Image Will be Stored In S3.

Make a CloudFront URL for that Images

Note: This is Haft of the code for CloudFront Rest Is Available on my Github repo: Click Here

Done Our Mini-Infrastructure Has Created Successfully!!

Goto to My Github For Complete Terraform File Here

To Run the Terraform File

  • Add Terraform Path to Environment Variable (For Windows Users)
  • Open Terminal And Navigate to The Folder Where .tf is Present
  • Type “Terraform Init” -This will install All required Plugins
  • Type “Terraform apply -auto-approve” -That’s it Now Your Infrastructure Will get Ready In minutes

Thanks For Reading 🙏

LinkedIn: Here

Tech. Explorer