---
title: TFNFR34 - Using Feature Toggles
description: Module Specification for the Azure Verified Modules (AVM) program
url: /spec/TFNFR34
type: default
tags: [
  Class-Resource, # MULTIPLE VALUES: this can be "Class-Resource" AND/OR "Class-Pattern" AND/OR "Class-Utility"
  Class-Pattern, # MULTIPLE VALUES: this can be "Class-Resource" AND/OR "Class-Pattern" AND/OR "Class-Utility"
  Class-Utility, # MULTIPLE VALUES: this can be "Class-Resource" AND/OR "Class-Pattern" AND/OR "Class-Utility"
  Type-NonFunctional, # SINGLE VALUE: this can be "Type-Functional" OR "Type-NonFunctional"
  Category-CodeStyle, # SINGLE VALUE: this can be "Category-Testing" OR "Category-Telemetry" OR "Category-Contribution/Support" OR "Category-Documentation" OR "Category-CodeStyle" OR "Category-Naming/Composition" OR "Category-Inputs/Outputs" OR "Category-Release/Publishing"
  Language-Terraform, # MULTIPLE VALUES: this can be "Language-Bicep" AND/OR "Language-Terraform"
  Severity-MUST, # SINGLE VALUE: this can be "Severity-MUST" OR "Severity-SHOULD" OR "Severity-MAY"
  Persona-Owner, # MULTIPLE VALUES: this can be "Persona-Owner" AND/OR "Persona-Contributor"
  Persona-Contributor, # MULTIPLE VALUES: this can be "Persona-Owner" AND/OR "Persona-Contributor"
  Lifecycle-BAU, # SINGLE VALUE: this can be "Lifecycle-Initial" OR "Lifecycle-BAU" OR "Lifecycle-EOL"
  Validation-TBD # SINGLE VALUE: this can be "Validation-TF/Manual" OR "Validation-TF/CI/Informational" OR "Validation-TF/CI/Enforced"
]
priority: 21340
---

## 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`:

```terraform
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:

```terraform
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 = []
}
```
