terraform
abstract
Terraform is a program which tracks and updates cloud-computing resources.
basics
- Repositories are folders containing source code files in Terraform's configuration language.
- Each module in a repository is defined by
main.tf
,outputs.tf
, andvariables.tf
files. -
Resources like buckets, computers, and networks are declared in
.tf
files. - Plugins for various cloud providers are used to provision resources.
- Text template files can substitute strings when commands are run.
-
State can be stored in local or remote
.tfstate
files.
commands
terraform apply [FOLDER] |
update all resources declared in [FOLDER] |
terraform console [FOLDER] |
start interactive console (for debugging) |
terraform destroy [FOLDER] |
deactivate every resource declared in [FOLDER] |
terraform fmt [FOLDER] |
autoformat all .tf files in [FOLDER] |
terraform init [FOLDER] |
install modules and do any necessary initialization |
terraform output [VARIABLE] |
show output variable(s) |
terraform plan [FOLDER] |
predict what apply [FOLDER] will do |
terraform show |
show current state (might include secrets!) |
terraform taint [RESOURCE] |
mark [RESOURCE] as broken, stale, and/or unsafe |
terraform untaint [RESOURCE] |
undo terraform taint [RESOURCE] |
dependencies
- Terraform binary file
examples
Autoformat staging
folder and check for errors.
terraform fmt staging terraform validate staging
Save an execution plan for the staging
folder, then show the plan in JSON format.
terraform plan -out myplan staging terraform show -json myplan
Destroy and rebuild some_resource
which was declared in the staging
folder.
terraform taint some_resource terraform apply staging
Apply changes to staging
folder without being prompted to confirm.
terraform apply -auto-approve staging
faq
- Where are the official docs?
- Terraform Commands (CLI)