Terraform Core Commands

Reading Time: < 1 minute

This page is work in progress


30th November 2018

Terraform commands

–help is help

Tab completion enabled by terraform -install-autocomplete

CommandWhat it does?
terraform -install-autocompleteEnables tab completion
-helpShows the help files
applyapply the changes
consolecreates and interactive console
destroydestroys the Terraform-managed infrastructure
fmtused to rewrite Terraform configuration files
force-unlockused to remove lock on the state for the current configuration
getused to download and update modules
graphused to generate a a graph
importused to import existing resources
initused to initilize a working directory
outputused to extract the value of an output variable
planused to create an execution plan
providersused to print information about providers (eg VMware, AWS, HyperV etc etc etc)
pushused to upload your configuration
refreshused to update the state of a file
showuseds to provide output from a state or plan file
stateused for advanced state management
taintused to mark resources as tainted
validateused to validate the syntax of terraform files
untaintused to unmark a resourse as tainted
workspaceused to manage workspaces


CommandWhat it does
listused to list all existing workspaces
selectused to choose different workspaces
newused to create a new workspace
deleteused to delete and existing workspace

Terraform Syntax

The syntax of Terraform configurations is called HashiCorp Configuration Language (HCL). It is meant to strike a balance between human readable and editable as well as being machine-friendly. For machine-friendliness, Terraform can also read JSON configurations

HCL Syntax (HashiCorp Configuration Language)

Here is an example of HashiCorp Configuration Language (HCL)

# An AMI

variable “ami” {

description = “the AMI to use”


/* A multi

line comment. */

resource “aws_instance” “web” {

ami = “${var.ami}”

count = 2

source_dest_check = false

connection {

user = “root”


} Source: https://www.terraform.io/docs/configuration/syntax.html

JSON Syntax

Terraform also supports JSON which is a machine friendly language


“variable”: {

“ami”: {

“description”: “the AMI to use”



“resource”: {

“aws_instance”: {

“web”: {

“ami”: “${var.ami}”,

“count”: 2,

“source_dest_check”: false,

“connection”: {

“user”: “root”





} Source: https://www.terraform.io/docs/configuration/syntax.html


Type or VariableWhat it does
"var" prefixUser String Variable
"var.MAP["KEY"]User Map Variable
Value of Key
"${var.LIST}"Value of the list as a list
List elements by Index
"self.ATTRIBUTE"Own Resource
"terraform.FIELD"Terraform Meta


You may also like...

1 Response

  1. 29/01/2021

    […] Terraform core commands […]

Leave a Reply

Your email address will not be published. Required fields are marked *