TFNFR34 - Using Feature Toggles
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.
E.g., our previous release was v1.2.1 and next release would be v1.3.0, now we’d like to submit a pull request which contains such new resource:
resource "azapi_resource" "route_table" {
type = "Microsoft.Network/routeTables@2023-11-01"
name = coalesce(var.new_route_table_name, "${var.subnet_name}-rt")
parent_id = var.parent_id
location = local.location
body = {
properties = {}
}
response_export_values = []
}A user who’s just upgraded the module’s version would be surprised to see a new resource to be created in a newly generated plan file.
A better approach is adding a feature toggle to be turned off by default:
variable "create_route_table" {
type = bool
default = false
nullable = false
}
resource "azapi_resource" "route_table" {
count = var.create_route_table ? 1 : 0
type = "Microsoft.Network/routeTables@2023-11-01"
name = coalesce(var.new_route_table_name, "${var.subnet_name}-rt")
parent_id = var.parent_id
location = local.location
body = {
properties = {}
}
response_export_values = []
}