skip to content
Alvin Lucillo

Conditional resource

/ 1 min read

If you maintain separate resources per context, like a workspace, you can segregate them using terraform modules. With conditional resource creation with count, you can tell terraform whether or not to create the resources. In the example below, if is_custom_module is true, then terraform will include the resources under that module in your terraform commands.

module "custom_module" {
  count  = local.is_custom_module ? 1 : 0
  source = "./modules/custom_module"
}