TIL — Conditionally enable a Terraform module

Karan Sakhuja
Knock Engineering
Published in
Jan 18, 2023

We can conditionally enable or disable a Terraform module for different environments using the count meta-argument.

variable "ENABLE_DB" { 
type = bool
default = true
}

module "database" {
source = "./modules/database"
# Conditionally enable module
count = var.ENABLE_DB ? 1 : 0
}

--

--