Skip to content

HCL

<BLOCK TYPE> "<BLOCK LABEL>" "<BLOCK LABEL>" {
  # Block body
  <IDENTIFIER> = <EXPRESSION> # Argument
}

Blocks

  • terraform: settings block
  • provider: providers config
  • resource: resources to be created
  • variable: define variables
  • output: output information to somewhere
  • data: allow data to be fetched or computed

Variables

  • Variables are defined in variable block
  • Default values are defined in the variable block, but they can be overwritten at runtime
# from literal
terraform plan -var "location=eastus"
terraform apply -var "location=eastus"

# from var file
terraform plan -var-file "terraform.tfvars"
terraform apply -var-file "terraform.tfvars"
  • terraform.tfvars and *.auto.tfvars files are automatically populated
  • Environment variables in the form TF_VAR_myvar are also automatically populated
location = "westus"
resource_group_name = "my-rg"