_
(underscore) instead of -
(dash) everywhere (resource names, data source names, variable names, outputs, etc).resource "aws_route_table" "public" {}
resource "aws_route_table" "public_route_table" {}
resource "aws_route_table" "public_aws_route_table" {}
this
if there is no more descriptive and general name available, or if the resource module creates a single resource of this type (eg, in AWS VPC module there is a single resource of type aws_nat_gateway
and multiple resources of typeaws_route_table
, so aws_nat_gateway
should be named this
and aws_route_table
should have more descriptive names - like private
, public
, database
).-
inside arguments values and in places where value will be exposed to a human (eg, inside DNS name of RDS instance).count
/ for_each
inside resource or data source block as the first argument at the top and separate by newline after it.tags,
if supported by resource, as the last real argument, following by depends_on
and lifecycle
, if necessary. All of these should be separated by a single empty line.count
/ for_each
prefer boolean values instead of using length
or other expressions.resource
count
/ for_each
tags
count
name
, description
, and default
value for variables as defined in the "Argument Reference" section for the resource you are working with.list(...)
or map(...)
.description
, type
, default
, validation
.description
on all variables even if you think it is obvious (you will need it in the future).number
, string
, list(...)
, map(...)
, any
) over specific type like object()
unless you need to have strict constraints on each key.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 to string
).any
to disable type validation starting from a certain depth or when multiple types should be supported.{}
is sometimes a map but sometimes an object. Use tomap(...)
to make a map because there is no way to make an object.{name}_{type}_{attribute}
, where:{name}
is a resource or data source name without a provider prefix. {name}
for aws_subnet
is subnet
, foraws_vpc
it is vpc
.{type}
is a type of a resource sources{attribute}
is an attribute returned by the output{name}
and {type}
there should be as generic as possible (this
as prefix should be omitted). See example.description
for all outputs even if you think it is obvious.sensitive
argument unless you fully control usage of this output in all places in all modules.try()
(available since Terraform 0.13) over element(concat(...))
(legacy approach for the version before 0.13)output
this
should be omitted in the name of output: