Terraform Cheatsheet
This post explains how to set up a shortcut for Terraform in the terminal and the Terraform commands I use the most.
Create an alias for TF in your Terminalโ
Add an alias to your shell profile so you can type tf instead of terraform:
- PowerShell
- Bash
New-Alias -Name tf -Value terraform -Force
alias tf=terraform
๐ See my full Terraform shortcuts (with tffmt, tfa, tfd) in Terraform Shortcuts.
TF Commandsโ
| Command |
|---|
tf init |
tf fmt --recursive |
tf plan -out plan.out |
tf apply -auto-approve |
tf destroy -auto-approve |
tf state ls |
tf state rm ADDR |
tf import -var-file=[FILENAME].tfvars ADDR ID |
Examplesโ
TF IMPORTโ
terraform [global options] import [options] ADDR ID -> Is the resource path as RESOURCE_TYPE.RESOURCE_NAME. Examples:
aws_resourcegroups_group.main
aws_organizations_organizational_unit.apps["journalbot"] -> Resources created without foreach.
module.app_envs["temp-app-envs"].aws_organizations_organizational_unit.envs["prd"] -> Resources created **with foreach**.
Using the ADDR in tf import:
- PowerShell
- Bash
tf import -var-file=base.tfvars RESOURCE_TYPE.RESOURCE_NAME ID_OR_ARN # Resources created without foreach.
tf import -var-file=base.tfvars 'RESOURCE_TYPE.RESOURCE_NAME[\"RESOURCE_KEY\"]' ID_OR_ARN # Resources created **with foreach**. Please note the `''` for the resource path.
tf import -var-file=base.tfvars RESOURCE_TYPE.RESOURCE_NAME ID_OR_ARN # Resources created without foreach.
tf import -var-file=base.tfvars 'RESOURCE_TYPE.RESOURCE_NAME["RESOURCE_KEY"]' ID_OR_ARN # Resources created **with foreach**. Please note the `''` for the resource path.
create symbolic linksโ
- PowerShell
- Bash
mklink link_name.tf original_file_path.tf # execute it in command prompt as admin
# TODO: fill
Referencesโ
About meโ
I'm a Senior Platform Engineer. I build and evolve Internal Developer Platforms โ golden paths, self-service tooling, and paved roads spanning AWS governance, CI/CD standardization, and developer enablement โ so engineering teams ship faster, safer, and more autonomously, with less cognitive load. My core stack is AWS, Terraform, and GitHub Actions, and I'm an AWS Certified Solutions Architect. I care deeply about paved roads, productivity, and documenting implementations so knowledge scales with the team (yes, I'm an engineer who likes to document ๐งโ๐ป).
You can check my experience here.
Personal Blog - cangulo.github.io
GitHub - Carlos Angulo Mascarell - cangulo
LinkedIn - Carlos Angulo Mascarell