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?
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Configuration files describe to Terraform the components needed to run a single application or your entire data-centre.
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 :
To Create an Infrastructure as Code to Start an AWS instance and Run apache server. Allow access to HTTP and SSH. The Images of Website should be stored in AWS S3 bucket with AWS CloudFront and The Files of Website should be Shored in Another EFS Storage that works as Backup.
- Create a Security Group that allows HTTP and SSH and a Key Pair
- Launch an Instance In EC2 and install Required Software in it. i.e. httpd, git, PHP, amazon-efs-utils.
- Create an EFS Storage as Backup and Mount it to /var/www/html
- Create an S3 Bucket and store the Images
- Make a CloudFront URL for that Images
Create a Security Group that allows HTTP and SSH and a Key Pair
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
- Download Terraform From Hashicorp From Here-
- 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 🙏
Connect With Me: