Advanced EC2 Configuration with Terraform

Advanced EC2 Configuration with Terraform

Or how to fine-tune your EC2 Instances on AWS with Terraform and Cloud Init.

Introduction

AWS EC2, short for Amazon Web Services Elastic Compute Cloud, is probably the most used service provided by Amazon. Therefore, I believe a look into how EC2 Instances can be configured via an Infrastructure as Code (IaC) tool will provide you with insight into how to both shorten and simplify the infrastructure setup process.

Terraform

Terraform is an IaC tool developed by HashiCorp used for provisioning, changing and versioning infrastructure. It uses a proprietary high-level syntax language, called HCL, to describe the infrastructure blocks.

Explaining how Terraform works and how to use it is beyond the purpose of this article. You can find a ton of step-by-step walkthroughs and tutorials in their guides.

Moving forward, I will assume that you are familiar with the basic concepts of Terraform. I will try to add links to learning resources when I feel it is necessary, but you can always reach out with questions.

Default EC2 Setup

Provisioning an EC2 Instance with Terraform is pretty straightforward. As prerequisites, you must firstly create an IAM profile, and give it the permissions your use case requires.