Terraform Cheat Sheet

Terraform Commands

Terraform Cheat Sheet

Syntax Usage: terraform [global options] <subcommand> [args]

1. Main Commands:

  • command: terraform init (used for initializing a working directory)
  • command: terraform plan (used to preview the action)
  • command: terraform apply (used to execute the actions proposed)
  • command: terraform destroy (used to destroy all the objects managed by terraform)

2. Other Commands:

  • command: terraform validate (used to validate configuration files in a directory)
  • command: terraform fmt (used to rewrite configuration files to canonical format and style)
  • command: terraform console (used for evaluating and experimenting with expressions on interactive command-line console)
  • command: terraform force-unlock (used to destroy all the objects managed by terraform)
  • command: terraform get (used to download and update modules)
  • command: terraform graph (used to generate a visual representation of either a configuration or execution plan)
  • command: terraform import (used to import existing infrastructure to manage from terraform )
  • command: terraform login (used to automatically obtain and save an API token for terraform cloud )
  • command: terraform logout (used to remove credentials stored by terraform login )
  • command: terraform providers (used to browse the provider's section of the terraform registry)
  • command: terraform refresh (used to read the current settings from the managed remote objects and update the state to match. )
  • command: terraform show (used to provide human-readable output from a state or plan file)
  • command: terraform state (used for advanced state management)
  • command: terraform taint (used to inform about a particular object has become degraded or damaged)
  • command: terraform untaint (used to remove that tainted condition from the resource)
  • command: terraform version (used to show the detail about terraform version installed in the system)
  • command: terraform workspace (used for advanced workspace management)

3. Sub-Commands (Options):

a) terraform init: terraform init [options]

  • command: terraform init -input=true (used to ask for input if necessary)
  • command: terraform init -lock=false (used to disable state file locking during state-related operations)
  • command: terraform init -lock-timeout=<duration> (Override the time terraform will wait to acquire a state lock)
  • command: terraform init -no-color (disable color codes in the command output)
  • command: terraform init -upgrade (used for updating provider versions)

b) terraform plan: terraform plan [options]

  • command: terraform plan -var 'NAME=VALUE' (used to sets a value for a single input variable declared in the root module of the configuration)
  • command: terraform plan -var-file=FILENAME (used to set the value for potentially many input variables declared in the root module of the configuration)
  • command: terraform plan -refresh=false (used to disable the default behavior of synchronizing the state file with a remote object before changes)
  • command: terraform plan -replace=ADDRESS (used to instruct terraform to plan to replace the resource instance with the given address)
  • command: terraform plan -target=ADDRESS (used to focus planning  efforts only on specified instances that match the given address)

c) terraform apply: terraform apply [options] [plan file]

  • command: terraform apply -auto-approve (used to apply the plan without asking for confirmation)
  • command: terraform apply -compact-warnings (used to show the summary message of any warning messages in a compact form)
  • command: terraform apply -input=false (used to disable all of terraform interactive prompts)
  • command: terraform apply -json (used to enable the machine-readable JSON UI output)
  • command: terraform apply -lock=false (don't hold a state lock during the operation)
  • command: terraform apply -lock-timeout=DURATION (used to instruct terraform to retry acquiring a lock)
  • command: terraform apply -no-color (used to disable terminal formatting sequences on the output)
  • command: terraform apply -parallelism=n (used to limit the number of concurrent operations as terraform walks the graph)
  • command: terraform apply -state=FILENAME (used to override the state filename when reading the prior state snapshot)
  • command: terraform apply -state-out=FILENAME (used to override the state filename when writing new state snapshots)
  • command: terraform apply backup=FILENAME (used to override the default backup filename that the local backend would normally use when creating a new backup file)

---

Thanks & Regards,

Kanchan Soni (https://linktr.ee/kanchansoni)

(A girl who saw the dream with an open eye to compete with self-capability in the area of IT and its Next-Gen Technology, with the ability to complete the task with perfection.)

Email: kanchansoni.cse@gmail.com



Comments

People also Look For

All about DevOps (A Complete Guide to DevOps)

How to Implement Microservice Coded In Hackathon Event

Upcoming DevOps trends

All about Cloud Computing