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:


The top reasons I decided to switch to VS Code as my editor of choice.

Image for post
Image for post
Photo by Riku Lu on Unsplash

To give some additional context, my previous text editor of choice was Sublime Text 3. I swore by it (mostly due to ignorance) and used it for all of my code editing. If I ever found a feature missing I was always just another package away from finding what I needed. However, over time Sublime Text 3 became less and less stable the more packages I added.

Eventually, it became tiring to use an unstable text editor that missed many of the features I wanted. That is when I came to terms with the fact that Sublime Text is just a text editor and most of the features I wanted would come from something closer to an IDE. …


A quick guide for first timers trying to deploy from your local machine to elastic beanstalk.

Image for post
Image for post
Photo by SpaceX on Unsplash

Install the CLI

First, you need to install the eb cli.

pip install awsebcli --upgrade --user

or

bre install awsebcli

Next, you need to modify your PATH.

Linux:

export PATH=~/.local/bin:$PATH

Mac OS:

export PATH=~/Library/Python/3.7/bin:$PATH

You may want to close and reopen your CLI at this point to source.

Configure Your CLI

Now you will want to run the below command in the directory that your code is in.

eb init

You will want to input your region and if you do not have access keys you will want to create them in your AWS account and enter them here. …


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


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


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.


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. …

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