Hashicorp Configuration Language: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 21: Line 21:
</syntaxhighlight>
</syntaxhighlight>


This is also an expression interpolation, prefixed with “var.”
This is also an [[#Interpolation_Expression|interpolation expression]], prefixed with “var.”


Variables can be assigned in multiples way, and this is the descending order of precedence:
Variables can be assigned in multiples way, and this is the descending order of precedence:
command-line flags (-var = ‘region=something’)
* command-line flags (-var = ‘region=something’)
from a file (.tfvars, -var-file=…) terraform.tfvars or *.auto.tfvars in the current directory are automatically loaded. Multiple -var-file can be used.
* from a file (.tfvars, -var-file=…) terraform.tfvars or *.auto.tfvars in the current directory are automatically loaded. Multiple -var-file can be used.
From environment variables: TF_VAR_name. This can only be used for string variables.
* From environment variables: TF_VAR_name. This can only be used for string variables.
UI Input
* UI Input
Variable defaults (“default” keyword).
* Variable defaults (“default” keyword).


Lists
==Lists==
{{External|https://learn.hashicorp.com/terraform/getting-started/variables#lists}}


https://learn.hashicorp.com/terraform/getting-started/variables#lists
==Maps==
 
{{External|https://learn.hashicorp.com/terraform/getting-started/variables#maps}}
Maps
 
https://learn.hashicorp.com/terraform/getting-started/variables#maps


=Output Variable=
=Output Variable=

Revision as of 23:08, 13 November 2019

External

Internal

Overview

Block

Interpolation Expression

Input Variable

variable "region" {
  default = "us-east-1"
}

To use the variable:

region= var.region

This is also an interpolation expression, prefixed with “var.”

Variables can be assigned in multiples way, and this is the descending order of precedence:

  • command-line flags (-var = ‘region=something’)
  • from a file (.tfvars, -var-file=…) terraform.tfvars or *.auto.tfvars in the current directory are automatically loaded. Multiple -var-file can be used.
  • From environment variables: TF_VAR_name. This can only be used for string variables.
  • UI Input
  • Variable defaults (“default” keyword).

Lists

https://learn.hashicorp.com/terraform/getting-started/variables#lists

Maps

https://learn.hashicorp.com/terraform/getting-started/variables#maps

Output Variable