Better Programming

Advice for programmers.

Follow publication

Member-only story

Reusable EC2 Instances Using Terraform Modules

A guide to mastering EC2 restructuring

Michael Cassidy
Better Programming
Published in
7 min readJul 5, 2022

--

In this project, we will go through a simple restructuring of an EC2 Instance template forked from GitHub. We will recreate the code using modules to make it more reusable and adaptable to a development or production environment. We will also go through how to remotely store our Terraform state file in Terraform Cloud to ensure the state data can be shared between all members of a team.

I will be using Visual Studio Code as my IDE, but feel free to use Cloud9 or another IDE of your choice. The steps in this tutorial will differ slightly if you choose to use a different IDE.

Prerequisites

  • AWS Account
  • Proper Permissions for your user
  • GitHub Account
  • GitHub personal access token
  • Terraform installed on your IDE
  • AWS CLI installed and configured on your IDE
  • Terraform Cloud Account

Set Up

If you would like to fork the repo from the following link, now is the time to do so. If not, simply copy the main.tf file and paste it into your IDE, and skip the next few steps:

--

--

Michael Cassidy
Michael Cassidy

Written by Michael Cassidy

60 Second Workouts™ | DevOps Architect | Certified Personal Trainer | Fitness Coach for Tech Leaders | https://michaelcassidy.co/

No responses yet

Write a response