Terraform
I started working on a new projects that relies on terraform and AWS. This is new to me, I’m used to Google Cloud and “artisanal” setup, by hand with scriping tools like Python’s Fabric or Ansible.
Basic commands
terraform fmt # format the files
terraform validate
terraform plan
terraform apply
terraform show # shows the current state, from the file terraform.tfstate. Might be sync'd with a remote
Concepts
Provider
Something like AWS, GCloud, etc. These are Cloud Provider.
Terraform translates “high-level” infrastructure operations into a provider operations using a translation layer. This translation layer is a Provider plugin.
Resource
A resource is a piece of something in your infra, it’s hardware, software, etc. It is prefixed by a provider.
Data
Module
In my project, modules have a main.tf
, outputs.tf
, variables.tf
. Example in Olivier’s DynamoDB Module.
Medium Article About Modules gives a few info, and it also shows they did it BEFORE the for_each
implementation.
If you find terraform code from before v0.12 (July 2018) it might be useful.
[Ouputs]
Similar to return values, can be used to feed back data to parent module, or show stuff on the CLI.
Approach
An interesting approach (TODO: reference its author), is to have multiple layers (components / applications) and have multiple environment (dev, prod, staging).
A script “compiles” the layer for each environment. Say the GraphQL API for the dev env. Which might have different endpoints URL than the prod one.
It relies on a compiler ala Jinja, pretty cools. Looks like maestro-ng
from my Docker time.
Questions
Terraform tutorial shows how to setup an nginx in docker. How does it relates to docker-compose.yml
?
What’s the point of having the terraform Cloud account?
What happens on error? Does terraform rollback?
Laurent Senta
I wrote software for large distributed systems, web applications, and even robots.
These days I focus on making developers, creators, and humans more productive through IPDX.co.