Launching the complete infrastructure in AWS using Terraform
# What is Terraform ?
Terraform is an open-source infrastructure as code software tool created by HashiCorp. It enables users to define and provision a datacenter infrastructure using a high-level configuration language.Terraform enables you to safely and predictably create, change, and improve infrastructure.
Step 1 : create aws profile
Here we have to give you IAM accounts access key and secret key and the region .
Step 2 : creating key using terraform
Here we used three resources tls_private_key(it basically generates secure private key), aws_key_pair( This key pair’s public key will be registered with AWS to allow logging-in to EC2 instance which is created by tls_private_key),local_file( it store private key in local computer so we can login to EC2 instance using openssh).
Step 3: Creating security group
This will create security group which allows HTTP protocol having port 80 and SSH protocol having port 22.
Step 4: Creating S3 bucket
Here we created s3 bucket with private policy so no one can access it and only can be accessible for cloud front to do that we have to create origin access identity and need to update bucket policy.
Step 5: Creating Origin access identity,bucket policy
To access bucket with cloudfront we created origin access identity and bucket policy.
Step 6: Creating Cloudfront distribution
This cloudfront distribution converts HTTP request to HTTPS.
Step 7: Getting cloudfront Url
Run the cmd : terraform init and terraform apply
It give you cloudfront url and now go to github update links of static file which is in s3 bucket.
Step 8: Creating EC2 instance
Step 9: Creating ebs volume and attaching to EC2 instance
Step 10:Server configuration in ec2 instance
we are installing web server in EC2 instance,formatting EBS volume and dowloading github code in /var/www/html directory
we need Ip of ec2 instance run the command :terraform init and terraform apply -auto-approve at the end we will get ip paste it in you browser you will see our website.
GitHub Link : https://github.com/rohitraut3366/terraform_aws_ec2
Thanks.