Skip to content

tmclnk/terraform-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Basics

  • Hashicorp Configuration Language HCL
    • Not YAML
    • Declarative
    • Typed - strings, numbers, lists, maps
  • Providers for different platforms
  • Modules
  • Data Lookups
    • look up latest machine image for an OS
    • look up things you created by hand, e.g. domains you registered

What Terraform Doesn't Do

Terraform does not do things like...

  • Conditional if/then creation logic
  • Provide swappable configuration across cloud providers
  • Provide a GUI
  • Configure VMs (use ansible, chef, puppet)

Also worth noting, terraform could be run from a CI/CD pipeline, but probably shouldn't. If you have a ton of resources, you can compose them together and script them, but generally speaking, you'll be doing terraform apply with hands-on-keyboard.

How Do I Use This

Install Terraform

Install Terraform CLI

Or use brew, apt, yum, or whatever. You'll (probably?) need Python 3.

The Jetbrains plugin for terraform is excellent. The VSCode plugin is also good. I used plain vim for about a year and was reasonably productive.

Terraform CLI

# You'll need AWS keys and permissions to create resources....
# I've got keys in a profile called "pg-tom"
export AWS_PROFILE=pg-tom

# Run from the directory of the env
cd environments/dev

# Initialize the plugin the first time and create any .tfstate files
terraform init

Creating and Modifying Resources

The usual development cycle once the directory is created is

# preview changes before applying, like a dry-run
terraform plan

# apply the changes. some resources, like databases and caches, can take
# several minutes to create; don't panic
terraform apply

Cleaning Up

terraform destroy

What Does This Create

  • A VPC spread across two AZs with 4 subnets in each VPC (public, private, database, cache). Routing tables between the subnets. This is roughly the network topography you'd expect if applying the AWS Well Architected Framework.
  • A small EC2 instance
  • A Postgres database
  • A Redis cache
  • An EKS Cluster (maybe, if I get to it)

Alternative Technologies

Terraform overlaps in different ways with...

  • The AWS CLI
  • AWS Libraries (namely boto3)
  • The AWS Console
  • CloudFormation (most similar)

Links

About

Some terraform examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages