ID: TFNFR30 - Category: Code Style - Handling Deprecated Outputs Sometimes we notice that the name of certain output
is not appropriate anymore, however, since we have to ensure forward compatibility in the same major version, its name MUST NOT be changed directly. It MUST be moved to an independent deprecated_outputs.tf
file, then redefine a new output in output.tf
and make sure it’s compatible everywhere else in the module.
ID: TFNFR32 - Category: Code Style - Alphabetical Local Arrangement Expressions in locals
block MUST be arranged alphabetically.
Good examples:
locals {
name = coalesce ( var . name , "name" )
tags = merge ( var . tags , {
env = "prod"
})
}
locals {
tags = merge ( var . tags , {
env = "prod"
})
}
locals {
name = coalesce ( var . name , "name" )
}
ID: TFNFR34 - Category: Code Style - Using Feature Toggles A toggle variable MUST be used to allow users to avoid the creation of a new resource
block by default if it is added in a minor or patch version.
ID: TFNFR35 - Category: Code Style - Reviewing Potential Breaking Changes Potential breaking(surprise) changes introduced by resource
block
Adding a new resource
without count
or for_each
for conditional creation, or creating by default Adding a new argument assignment with a value other than the default value provided by the provider’s schema Adding a new nested block without making it dynamic
or omitting it by default Renaming a resource
block without one or more corresponding moved
blocks Change resource
’s count
to for_each
, or vice versa Terraform moved
block
could be your cure.
ID: TFNFR4 - Category: Composition - Code Styling - lower snake_casing Module owners MUST use
lower snake_casing
for naming the following:
Locals Variables Outputs Resources (symbolic names) Modules (symbolic names) For example: snake_casing_example
(every word in lowercase, with each word separated by an underscore _
)
Module owners MUST use the below tooling for unit/linting/static/security analysis tests.
These are also used in the AVM Compliance Tests.
ID: TFNFR7 - Category: Code Style - count & for_each Use We can use count
and for_each
to deploy multiple resources, but the improper use of count
can lead to
anti pattern
.
You can use count
to create some kind of resources under certain conditions, for example: