Terraform from the beginning: notes from my first AWS EC2 deployment - Part 1

Table of Contents

I found myself wanting to convert a cloudformation config file to terraform and realised I haven’t worked with terraform before.

So let’s fix that by finding a beginner’s guide to getting your hands dirty with Terrafom.

I found and started following @gruntwork’s “Introduction to Terraform”. Admittedly its from 2016 and was bit outdated, but I was already halfway through it before I checked how current it was :)

No matter, learning is learning so here are my notes getting started with Terraform from my laptop.

Setup

Pre-requisite of things you need setup before you can deploy anything to the cloud.

aws account

iam user with limited permissions (AmazonEC2FullAccess)

AWS_SECRET_KEY and AWS_ACCESS_KEY of your iam user

terraform installed

AWS Account

setup your AWS user account

you need programmatic access

download the credentials.csv with your KEY and SECRET.

minimum ‘AmazonEC2FullAccess’ permissions

DONT use your root account, create another user account with min. privileges to play around with.

Terraform installed

make sure you’ve got terraform installed

[email protected]:~/development/cloudworld/terraform $ terraform
Usage: terraform [--version] [--help] <command> [args]
The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.
Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure

Terraform ‘init’

if you’ve never run terraform before you will probably need to run ‘terraform init’ in the folder you’re working in so terraform can pull down any plugins it needs for your particular project

[email protected]:~/development/cloudworld/terraform $ terraform init
Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "aws" (1.13.0)...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* provider.aws: version = "~> 1.13"
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.