In this post I'll create multiple resources in AWS cloud using Terraform. Terraform is an infrastructure as code(IAC) software which can do lots of things but it is superb in cloud automation. To use Terraform we have write code in a high-level configuration language known as Hashicorp Configuration Language, optionally we can write code in JSON as well. I'll create below service using Terraform-
1. Create the key-pair and security group which allow inbound traffic on port 80 and 22
2. Launch EC2 instance.
3. To create EC2 instance use same key and security group which created in step 1
4. Launch Volume(EBS) and mount this volume into /var/www/html directory
5. Upload index.php file and an image on GitHub repository
6. Clone GitHub repository into /var/www/html
7. Create S3 bucket, copy images from GitHub repo into it and set permission to public readable
8 Create a CloudFront use S3 bucket(which contains images) and use the CloudFront URL to update code in /var/www/html
After writing complete code below are the commands to execute and create infrastructure. This code work fine for deploy and destroy both.
$ terraform.exe init
$ terraform.exe plan
$ terraform.exe apply -auto-approve
GitHub URL - https://github.com/jay2tinku/hybrid__task1
Priyanshi@Priyanshi-PC MINGW64 /e/Training/Hybrid_cloud1/practice/terraform/task
$ ls -alh
total 53K
drwxr-xr-x 1 Priyanshi 197121 0 Jun 13 20:21 ./
drwxr-xr-x 1 Priyanshi 197121 0 Jun 13 12:30 ../
drwxr-xr-x 1 Priyanshi 197121 0 Jun 13 16:56 .terraform/
-rw-r--r-- 1 Priyanshi 197121 221 Jun 13 20:21 .terraform.tfstate.lock.info
-rw-r--r-- 1 Priyanshi 197121 18K Jun 1 09:52 Capture.JPG
-rw-r--r-- 1 Priyanshi 197121 4.4K Jun 13 19:38 task.tf
-rw-r--r-- 1 Priyanshi 197121 4.3K Jun 13 20:21 terraform.tfstate
-rw-r--r-- 1 Priyanshi 197121 158 Jun 13 20:21 terraform.tfstate.backup
1. Create the key-pair and security group which allow inbound traffic on port 80 and 22
2. Launch EC2 instance.
3. To create EC2 instance use same key and security group which created in step 1
4. Launch Volume(EBS) and mount this volume into /var/www/html directory
5. Upload index.php file and an image on GitHub repository
6. Clone GitHub repository into /var/www/html
7. Create S3 bucket, copy images from GitHub repo into it and set permission to public readable
8 Create a CloudFront use S3 bucket(which contains images) and use the CloudFront URL to update code in /var/www/html
After writing complete code below are the commands to execute and create infrastructure. This code work fine for deploy and destroy both.
$ terraform.exe init
$ terraform.exe plan
$ terraform.exe apply -auto-approve
GitHub URL - https://github.com/jay2tinku/hybrid__task1
Priyanshi@Priyanshi-PC MINGW64 /e/Training/Hybrid_cloud1/practice/terraform/task
$ ls -alh
total 53K
drwxr-xr-x 1 Priyanshi 197121 0 Jun 13 20:21 ./
drwxr-xr-x 1 Priyanshi 197121 0 Jun 13 12:30 ../
drwxr-xr-x 1 Priyanshi 197121 0 Jun 13 16:56 .terraform/
-rw-r--r-- 1 Priyanshi 197121 221 Jun 13 20:21 .terraform.tfstate.lock.info
-rw-r--r-- 1 Priyanshi 197121 18K Jun 1 09:52 Capture.JPG
-rw-r--r-- 1 Priyanshi 197121 4.4K Jun 13 19:38 task.tf
-rw-r--r-- 1 Priyanshi 197121 4.3K Jun 13 20:21 terraform.tfstate
-rw-r--r-- 1 Priyanshi 197121 158 Jun 13 20:21 terraform.tfstate.backup
Comments
Post a Comment
Please share your experience.....