Complete end-to-end Terraform Pipeline!

Source: Daniele Levis Pelusi via Unsplash

Prerequisite for this Pipeline to Implement

  • Some knowledge of AWS & Github.
  • It would be a plus point for you if you are having the knowledge of JSON, because, in this Pipeline, HCL (Hashi Configuration Language) has been used which is the native language for Terraform, & it is very similar to JSON.

Explanation of Terraform

Terraform works on declarative language, i.e. we just have to tell it what has to be done, it will automatically look into the situation & do that thing for us.

Terraform is intelligent because of the plugins for each of the providers it has, using them as API, it can interact with any of its providers.

List of steps in the Pipeline

  1. Setting up the Terraform Provider.
  2. Creation of Key-Pair for AWS Instance.
  3. Creation of Security-Group for AWS Instance.
  4. Creating an EC2 instance.
  5. Entering into EC2 Instance to install some software.
  6. Creating another EBS volume & attaching it to the EC2 instance.
  7. Mounting the EBS volume to the EC2 instance.
  8. Creating an S3 bucket.
  9. Uploading data into the S3 bucket.
  10. Creating an AWS CloudFront distribution for that data uploaded into the S3 bucket.

Code of the End-to-End Pipeline

Creating a Provider for the Terraform
Creating a public key!
Key Pair created in AWS!
Creating a security group!
Security Group created in AWS!
An instance is created & Software[git] is installed into it!
EC2 Instance is created & software is installed in it, verification for the same can be done by accessing the EC2 instance by whichever way is possible. For example SSH
Volume created by Terraform!
Proof of Volume Attached to the AWS EC2 instance, it can be verified by the name of the instance and the device name of the EBS volume used above!
External EBS volume created will be mounted to the EC2 instance in the folder “/var/www/html”!
Drive mounted on the same AWS Instance!
Code to create an S3 bucket!
S3 Bucket Created!
Code to upload data to S3!
File Uploaded by Terraform!
CloudFront Distribution Code!
CloudFront Distribution Created by Terraform!

Important Commands & Facts to run this code

  • You should have Terraform installed in your system!
  • After copying this code in a file, save that file with the “.tf” extension.
  • Run “terraform init” command.
  • Then run “terraform apply” to create your complete infrastructure!
  • Finally, when your work is completed, destroy your environment with the command “terraform destroy”.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store