TFNFR10 - No Double Quotes in ignore_changes
The ignore_changes
attribute MUST NOT be enclosed in double quotes.
Good example:
lifecycle {
ignore_changes = [
tags,
]
}
Bad example:
The ignore_changes
attribute MUST NOT be enclosed in double quotes.
Good example:
lifecycle {
ignore_changes = [
tags,
]
}
Bad example:
Sometimes we need to ensure that the resources created are compliant to some rules at a minimum extent, for example a subnet
has to be connected to at least one network_security_group
. The user SHOULD pass in a security_group_id
and ask us to make a connection to an existing security_group
, or want us to create a new security group.
An example from the community:
resource "azurerm_kubernetes_cluster" "main" {
...
dynamic "identity" {
for_each = var.client_id == "" || var.client_secret == "" ? [1] : []
content {
type = var.identity_type
user_assigned_identity_id = var.user_assigned_identity_id
}
}
...
}
Please refer to the coding style in the example. Nested blocks under conditions, MUST be declared as:
The following example shows how "${var.subnet_name}-nsg"
SHOULD be used when var.new_network_security_group_name
is null
or ""
Good examples:
coalesce(var.new_network_security_group_name, "${var.subnet_name}-nsg")
try(coalesce(var.new_network_security_group.name, "${var.subnet_name}-nsg"), "${var.subnet_name}-nsg")
Bad examples:
var.new_network_security_group_name == null ? "${var.subnet_name}-nsg" : var.new_network_security_group_name)
The naming of a variable
SHOULD follow
HashiCorp’s naming rule
.
variable
used as feature switches SHOULD apply a positive statement, use xxx_enabled
instead of xxx_disabled
. Avoid double negatives like !xxx_disabled
.
The target audience of description
is the module users.
For a newly created variable
(Eg. variable
for switching dynamic
block on-off), it’s description
SHOULD precisely describe the input parameter’s purpose and the expected data type. description
SHOULD NOT contain any information for module developers, this kind of information can only exist in code comments.
type
MUST be defined for every variable
. type
SHOULD be as precise as possible, any
MAY only be defined with adequate reasons.
bool
instead of string
or number
for true/false
string
for textobject
instead of map(any)
If variable
’s type
is object
and contains one or more fields that would be assigned to a sensitive
argument, then this whole variable
SHOULD be declared as sensitive = true
, otherwise you SHOULD extract sensitive field into separated variable block with sensitive = true
.
Nullable SHOULD be set to false
for collection values (e.g. sets, maps, lists) when using them in loops. However for scalar values like string and number, a null value MAY have a semantic meaning and as such these values are allowed.
nullable = true
MUST be avoided.