Launching WebPage using AWS | GitHub and Terraform
Brief About our task.
1. Create a key.
2. Creating VPC and 3 subnets in our VPC with enabled public IP.
3. Creating Internate gateway , routing table and associate with allsubnet.
4. Create a security group which allow the port 80 and port 22 for ssh.
5. Launch EC2 instance. In this EC2 instance use the key and security group which we have created in step 1.
6. Create one Volume using the EFS service and mount it in our VPC with all subnet and our security group attach it with our instance, then mount that volume into /var/www/html
7. Developer have uploded the code into github repo also the repo has some images.
8. Clon the github repo code into /var/www/html
9. Create S3 bucket, and copy/deploy the images from github repo into the s3 bucket and change the permission to public readable.
10. Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html
Pre-requisite:-
>>> Create an account on AWS
>>> Create a IAM user with Admin Access power and download the .csv file .
>>> Install AWS CLI on your base os (In my case i am using MacOS). Install AWS CLI using this link >>> https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html
>>> Install terraform in your base OS. Install terraform using this link >>> https://learn.hashicorp.com/terraform/getting-started/install.html
>>> Now configure aws then enter access key , Secret key and region. (On the place of ankit write your IAM user profile name)
>>> Now start creating terraform code.
>>> First create a folder And Create a vpc.tf file in that folder (You can write any name but extension must be .tf )
>>> open the aws.tf file in notepad(any editor) in my case i am using apple TextEditor.
Step: 1
>>> Give service provider name your IAM profile name and Create key.
Step: 2
>>> Creating VPC and subnet because want to launch our instance in our vpc and subnet and we require while creating EFS.
Step: 3
>>> Creating internet gateway which provide internet to to our vpc and create route table which IP to our subnet. And then associate with subnet to route table so that all subnet can get ip and internet.
Step: 4
>>> Create Security group which allow HTTP port 80 to access our web page and TCP port 3306 for ssh. Because without the security group we can’t launch our wordpress EC2 instance.
Step: 5
>>> Creating an instance then connect remotely through SSH using our created key after that install amazon-efs-utils(Need this software to mount efs), httpd, php and git because our website in php and we are using apache web server. Then we restart our service and then enabled permanent.
Step: 6, 7 & 8
>>> Create one Volume using the EFS service and mount it in our VPC with all subnet and our security group attach it with our instance, then connect remotely and mount EFS to /var/www/html
>>> For more details refer our first article Click here
Step: 9
Step: 10
>>> To get output of ip
>>> Now apply code using terraform apply -auto-apply command.
>>> Now we search our ip/ankit.html(13.233.47.51/ankit.html) in any browser and can access our webpage.
?
>>> Now you can Destroy whole infrastructure just from applying terraform destroy -auto-approve command .
>>> Thanks for reading my article. I hope it will help you. Please give your feedback.