Image for post
Image for post
Photo by La-Rel Easter on Unsplash

Hey guys! I wanted to do a quick tutorial on how I created an EC2 module for Terraform. If you want to see the repository it is located in check it out here. This module will do a few things:

  1. Create an EC2 Instance
  2. Automatically look up the latest Windows Server 2019 AMI for the EC2 instance.
  3. Create and attach a additional drive.
  4. Create a Cloudwatch Alarm Metric to monitor CPU.

The folder structure looks like this:

Image for post
Image for post

First things first… I created the main.tf file which contains all of my configuration except for the variables and outputs. The main.tf …


Image for post
Image for post
Photo by Nico Smit on Unsplash

If you missed the first 3 workshops, find them here. Here are 3 more AWS Workshops you didn’t know existed.

These are workshops that I have discovered, but have not yet taken the time to complete. I would love to hear about your experiences with them. My hope is that by spreading some awareness of their existence you can learn a ton… for free!

Don’t forget to always clean up your environments to avoid a high bill!

Real Time Streaming with Amazon Kinesis

Image for post
Image for post

This workshop has labs for the following:

  • Ingestion
  • Kinesis Firehose
  • Data analytics
  • Real-time stream processing pipeline

Find the Kinesis workshop here.

Dynamo DB

Image for post
Image for post

Topics for this workshop…


AWS has a ton of documentation, labs, examples, etc. So much so that it is difficult to find the best material to follow. Here are some exceptional workshops catered to helping you learn.

Image for post
Image for post
Photo by Jeswin Thomas on Unsplash

EKS Workshop

Image for post
Image for post

You can find this workshop here. It covers:

  • Deployments
  • Health checks
  • Dashboards
  • Exposing services
  • Deploying Jenkins
  • CI/CD Pipelines
  • X-Ray
  • Service Meshes
  • Tons more!

These workshops are a huge hidden gem of AWS and I am shocked that I didn’t know about them earlier.

ECS Workshop

Image for post
Image for post

This one can be found here.

This I actually completed just yesterday so I know a bit more about this one. For this one I setup an application using ECS on Fargate. It creates a frontend (node.js I believe), then a back end. Then you end up scaling both up all the while seeing everything update in a map the the app creates. …


Sometimes your AWS resources predate your Terraform code. Let’s talk about how to import those pre-existing resources into Terraform.

Image for post
Image for post
Photo by The Creative Exchange on Unsplash

The first thing we are going to want to do is identify what resources need to be imported. In this case, let’s import an S3 bucket.

Before we get started make sure your AWS CLI is configured correctly. You can do this by quickly running aws s3 ls to list any buckets.

Image for post
Image for post

Choose Resource to Import

I will be importing an S3 bucket called import-me-pls.

Image for post
Image for post

Create Terraform Configuration Code

First I will set up my provider block:

provider "aws" {
region = us-east-1
}

Then the S3 bucket configuration:

resource "aws_s3_bucket" "import_me_pls" {
bucket = "import-me-pls"
acl = "private"…


My experience with Terraform upgrades from version 0.11 to 0.12 have been really frustrating, until now.

Image for post
Image for post
Photo by Tim Gouw on Unsplash

Upgrading Terraform from version 0.11 to 0.12 has been a pain in the butt every time I have done it. (and I have done it many times)

Every time that I go through the process I learn a little something more that makes it a little easier.

Before You Begin

Before you even get started there is something you need to fix with module naming. …


Ready to automate your CDN deployment for an S3 website bucket? Let’s build a module to do it for you!

Image for post
Image for post
Photo by Timothy Ah Koy on Unsplash

If you want to skip all of the fun the repo with the code we are using is located here. Also, before you get started here go check out my article on creating an S3 website bucket module. This article will be building on the groundwork set there and will assume you have an S3 bucket module.

S3 Bucket Code

For this article, I am going to assume that you already have an S3 website created and just want to get it deployed to Cloudfront using Terraform. …


Alrighty peeps, let’s create an S3 website module for Terraform! Want to see my code? Find it here!

Image for post
Image for post
Photo by Marina Khrapova on Unsplash

Creating the Provider Block

First we are going to need to create the provider code block in our main.tf.

provider "aws" {  
version = "~> 2.0"
region = var.region
}

Here we made sure to set region to var.region so that we can specify the region in our child modules.

Creating the S3 Bucket

Now we need to add in the code block for our S3 Bucket.

resource "aws_s3_bucket" "prod_website" {  
bucket_prefix = var.bucket_prefix
acl = "public-read"
website {
index_document = "index.html"
error_document = "error.html"

}
}

Now in this block you can see that we set a variable for bucket, but just set public-read for our acl. We want to make sure that we can set a value for bucket_prefix in the child module which is why we set a variable here. …


So, today I discovered how to automate running a terraform fmt and committing it using Github actions!

Image for post
Image for post
Photo by Alex Knight on Unsplash

Github Actions

If you are not aware, GitHub actions are actions that GitHub can run for you automatically to perform various…. actions. These actions will be computed on some virtual machine far far away for just the amount of time needed to perform your action.

If you already know how to setup GitHub actions, you can go find my YAML file here. Find terraform-fmt-commit.yml in that folder.

Terraform fmt Setup

Terraform is a great human-readable language for creating infrastructure, but it’s still not easy to read if it isn’t formatted correctly. …


My favorite tools to use in conjunction with Terraform.

Image for post
Image for post
Photo by Barn Images on Unsplash

TFSwitch

This is an amazing tool from Warrensbox which you can find on Warren’s website here or on the github repo here.

Tfswitch allows you to switch between different versions of Terraform on the fly. In addition to switching between Terraform versions tfswitch will download any version of Terraform you do not have installed if the version is selected.

Here are a couple of gifs from Warren’s github README that demonstrate how it is used.

Image for post
Image for post

To check out the tool and find more information on usage go check out the repo! …


So you heard about Hashicorp Terraform and decided you want to try it out? Here is a comprehensive guide to getting started.

Image for post
Image for post
Photo by Gia Oris on Unsplash

Before we can even get started using Terraform we need to first create an account for a cloud service to use it with. You can use AWS, Azure, or GCP to get started. I’ll provide some instructions for AWS.

Create an AWS Account

Go to the AWS Console and click Create an AWS Account.

Image for post
Image for post

You may need to click Create a New AWS Account as seen in the image below.

Image for post
Image for post

Next, you will be prompted to create your account and name it.

Image for post
Image for post

Now you need to choose the appropriate account…

About

Jake Jones

Terraform | DevOps | AWS

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