Setting up an AWS infrastructure using Terraform

Setting up an AWS infrastructure using Terraform

SETUP YOUR PROFILE / SOFTWARE

  • Firstly, you would need to create an IAM user (ishan_tf in my case). Note down the Access Key ID and Secret Access Key (you will need it to configure the profile on was cli).
  • Create a key pair and a security group that allows inbound SSH and HTTP.
  • Download the AWS cli and Terraform onto your system.

Use #aws configure --profile ishan_tf (profilename) and paste your access keys here.

No alt text provided for this image

Windows users can add the terraform path to environment variables, where as Linux users can simply unzip and #chmod +x terraform #mv terraform /usr/bin

NOW THAT WE HAVE OUR SYSTEM SET UP, LETS CODE!

(Create a .tf extension file)

  • Create an S3 bucket and configure its policy to public-read.
No alt text provided for this image
  • Configure Jenkins to get images from github to S3 bucket.

We need the S3 publisher plugin

No alt text provided for this image

Configure it

No alt text provided for this image

Create a job to transfer contents to the s3 bucket.

No alt text provided for this image
No alt text provided for this image
  • We need to trigger this after our bucket is created.
No alt text provided for this image
  • Create a CloudFront distribution.
No alt text provided for this image
No alt text provided for this image
  • Remember to use the domain generated for your image src in HTML.
  • Create an EC2 instance and install services like httpd PHP git.
No alt text provided for this image
  • Create and attach EBS to it.
No alt text provided for this image
  • Partition, format, and mount it to /var/www/html/ to make the data persistent. Also, clone the developers' code to the folder.
No alt text provided for this image
  • We can also output or store the IP of the instance here.
No alt text provided for this image
  • Now that we have set up the infrastructure code, let's run it.

#terraform init (initialize a working directory containing Terraform configuration files.)

#terraform validate (validates the configuration files in a directory).

#terraform apply (apply the changes required to reach the desired state of the configuration).

No alt text provided for this image
  • And here it is!
No alt text provided for this image


To view or add a comment, sign in

More articles by Ishan Singhal

Others also viewed

Explore content categories