Infrastructure as code by using Terraform.
What is terraform ?
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.We use terraform to manage the services of Aws,Gcp Azure & openstack etc.
Task by using terraform:-
1- Create a key pair and security group which allow 80 port.
2-Launch EC2 Instance by using key & security group which completed step 1.
3-Launch one Volume (EBS) and mount that volume into /var/www/html.
4-Developer have uploded the code on github repo. Also the repo has some images.
5-Copy the github repo code into /var/www/html.
6-Create S3 bucket, and copy/deploy the images from github repo into the s3 bucket and change the permission to public readable.
7-Create a Cloudfront using s3 bucket(which contains images) and use the Cloudfront URL to update in code in /var/www/html.
Let’s do our task.
Note- for running code by using terraform everytime we need a access key and secret key. but most of time we have to share our code to our team but we don’t want to share our keys so for security purpose we can create aws profile and use it instead of using our keys.
1-Create a key pair and security group-
firstly we will use ssh-keygen it will generate public and private key for you and copy the public key from the file and paste in notepad
2-Create security group -
3-launch EC2 by using key and security group which we have done in 1 step & install webserver-
4-Now we will launch EBS and attach to instance then mount /var/www/html & clone github code in /var/www/html
5-Now we will create s3 bucket and upload the images into it-
6-Create a cloud front using s3 -
The url we get from cloud front we put it in our github then.
Output-
Task 1 done
Thanks.
Thanks to Vimal Sir.