Launching website just in one click
by the help of terraform,aws and github integration.
Before read the article you can see the practical of my article::
What is terraform??
in today’s world we use different tool for manage the services of cloud,but various types of tools are available in the it (information technology) sector for managing the cloud services.but in all terraform is best.
because we can access any cloud like private and public by the using of terraform ,so you don’t have need to learn more languages for access the cloud services.for this terraform provided HCL (HashiCorp Configuration Language).hcl language is similar like json.
“Terraform is a tool which can contact any cloud, for this we use code (hcl) inside terraform”.
DOCKET (launching website by using terraform ,aws and github.)
1.create key pair and security groups for launching the instance on cloud ,keypair we use for launching the instance and security groups we use for give the permission to the outside user so he can access our instance web server , for this we allow port 80 (http protocol) and we also allow port 22(ssh protocol) for remote login.
2.launch ec2 instance.
3.launch httpd web server inside the instance.
4.Launch one Volume (EBS) and mount that volume into /var/www/html folder of our instance web server(httpd).
5.create one repo in github which should be public ,in this repo we have some photo and code of our website.
6.copy this pics and code in the folder of var/www/html (web server).
7.Create S3 bucket, and copy/deploy the images from github repo into the S3 bucket and change the permission to public readable.
8.for static data like images and videos we use cloud front which pick these data from s3 bucket and provide to the edge location of aws. (content delivery network).
9.after this whole setup we can launch the website in just one click.
Required tool and accounts ..
you have a account on github,for uploading files and static data.
you have a aws account for access the cloud services.
you have terraform.exe tool in your system.
STEP 1:
in this 1 step i use my credential for connect to the my aws account thow the aws cli and window command prompt.
STEP 2:
i have created on folder for this task ,inside this folder i have terraform.exe tool and all hcl language .tf files,i have create seperate .tf files for each service of cloud ,but we can write all codes in one single .tf file.
Add alt text
STEP 3:
now we access the location of our folder which we create above.after access this folder we type command
terraform init
for initialize the terraform ,and terraform download the plugins by this command according to your code.
Add alt text
STEP 4:
CREATING SECURITY GROUP
here i created one security group means firewall of your instance by this security group we can give multiple permission like inbound and outbound.
inbound is known as ingress(incoming traffic from outside) , in ingress i have give permission to the http protocol (port 80) for connecting to the outside traffic and we also give permission to the ssh protocol(port 22) for remote login.
outbound is known as egress, its allow traffic to go outside from your instance to outside world.in this i have give same permission which i give to the ingress above.
Add alt text
STEP 5:
i created variables which i use anywhere wherever its need will come.
Add alt text
STEP 6:
Launch ec2 instance by using variables .
after download of instance it download httpd web server and git inside your instance,security group which we created above we use in this code .
Add alt text
STEP 7:
elastic block storage:
now we create one ebs(elastic block storage) ,it work as a pen drive,we attach this ebs to the ou instance and mount this ebs to the folder of httpd server folder var/www/html and clone this folder to the github repo.so whenever developer upload any code or pics it can copy these data into your http server html folder.
Add alt text
STEP 8:
Create S3 bucket, and copy/deploy the images from github repo into the s3 bucket and change the permission to public readable.
here we create one s3 bucket , s3 bucket is a one kind web service of aws,in s3 bucket your data is more secure and in s3 u can store unlimited data.s3 bucket mostly used for static data like images ,videos.so first we download the static data from your github repo to in your local machine.and then we upload this data in s3 bucket,throw the code.
STEP 9:
now we create cloudfront for cdn.
we use cloud front for provide our website data to the different countries edge location it is also known as content delivery network,we connect clou front to the s3 bucket so it takes static data from your s3 bucket and provide this static data to the different edge location,it takes some time when first user use this content in any particular new location. but when this first user get the content then this data create a cache in particular location and when any new user of particular location again access this content then its not take time.
Step 10:
creating snapshot of ebs:
we create the snapshot of our ebs because instance which we create above is stable in a particular fixed location so our ebs is also should be have a in same location but after creating the snapshot of ebs any developer in any region can use this snapshot in their own instance.
OUTPUT::
after applying command
terraform apply -auto-approve
you got a ip of your instance in one file and got a cloudfront domain name in your folder.
and automatic your website launch in your default browser.
Add alt text
this is the outcome of my practical.
“Thanks for reading”