- Hashicorp Configuration Language HCL
- Not YAML
- Declarative
- Typed - strings, numbers, lists, maps
- Providers for different platforms
- Providers provide "resources", e.g. aws provider
- Modules
- Group resources together
- Modules have Input Variables
- Modules have outputs, e.g. EKS Attributes
- Data Lookups
- look up latest machine image for an OS
- look up things you created by hand, e.g. domains you registered
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.
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.
# 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
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
terraform destroy
- 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)
Terraform overlaps in different ways with...
- The AWS CLI
- AWS Libraries (namely boto3)
- The AWS Console
- CloudFormation (most similar)