Interview Prep/Terraform/Repository Structure, Environments and Module Strategy

How do you implement feature toggles in a module?

BeginnerProductionRepository Structure, Environments and Module Strategy
Answer

Boolean variables feeding count or for_each, with outputs using one() to return null when off.

variable "enable_waf" { type = bool  default = false }
resource "aws_wafv2_web_acl" "this" { count = var.enable_waf ? 1 : 0 /* ... */ }
output "waf_arn" { value = one(aws_wafv2_web_acl.this[*].arn) }

Keep toggles few and meaningful; too many produce untestable combinations.

All Terraform questions Roadmap: Terraform in production

More on Repository Structure, Environments and Module Strategy