Variables & Outputs
Variables
-
All input variables must contain
type
anddescription
arguments -
To ensure a variable is required, omit the
default
argument from the declaration. >Note: It may also be worth considering the disallowing ofnull
make sense. -
Order arguments in a variable block like this:
description
,type
,default
,validation
. -
Prefer using simple types (number, string,
list(...)
,map(...)
,any
) over specific type likeobject()
unless you need to have strict constraints on each key. -
Use specific types like
map(map(string))
if all elements of the map have the same type (e.g.string
) or can be converted to it (e.g.number
type can be converted tostring
) -
Use the plural form in a variable name when type is
list(...)
ormap(...)
. -
Where input is subjective, or where specific behaviour needs to be prevented, variable validation should be used. > Note: more variable validation examples can be found here
Outputs
-
All output values should consistent and understandable outside its scope. It should be obvious what type and attribute is returned.
-
The name of the output should describe the property it contains.
-
Use the plural form in a output name when type is
list(...)
. -
A good structure for the output name is
<name>_<type>_<attribute>
, where: <name>
is the resource or data source name without the provider prefixaws_subnet
issubnet
oraws_vpc
isvpc
<type>
is a type of resource sources-
<attribute>
is the attribute return by the output -
Always include a
description
for all outputs, even if you think its obvious. -
Prefer try() (available since Terraform 0.13) over element(concat(...)) (legacy approach for the version before 0.13)