7 Tips to Start Your Terraform Project the Right Way


1. Remote State

2. Separate Your Environments

3. Use Modules

4. Keep it DRY

5. Conditionals

Terraform plan output for create_bucket = false
Terraform plan output for create_bucket = true

6. The null_resource

7. Other Useful Functions

  • format() and formatlist() format a string or a list of strings. The following example left-pads the cluster_id with zeros to 4 digits
  • matchkeys(values, keys, searchlist) — filters a list of values with corresponding keys and returns only values that have keys in the searchlist. The following example returns a list of instances that are in the first zone.
  • element(list, index) — to access elements in a list variable (the [] notation also works). A neat “feature” of this function is that it wraps around the list, for example:


  1. Use remote state/backend
  2. Separate environments
  3. Use modules
  4. Keep it DRY (with tools like Terragrunt)
  5. Use conditionals for flexibility
  6. Use null_resource for edge cases (use sparingly)
  7. Use built-in interpolation functions



CDS Principal @ Slalom Build

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