Skip to content

Instantly share code, notes, and snippets.

@matt-FFFFFF
Created October 20, 2023 08:23
Show Gist options
  • Save matt-FFFFFF/c6454f2c1f60fbc5ccc75b22187ac203 to your computer and use it in GitHub Desktop.
Save matt-FFFFFF/c6454f2c1f60fbc5ccc75b22187ac203 to your computer and use it in GitHub Desktop.
Scenario selection with tf
variable "scenario" {
type = string
description = "Scenario to deploy. Must be one of 'simple', or 'complex'."
default = "simple"
validation {
condition = contains(["simple", "complex"], var.scenario)
error_message = "Scenario must be one of 'simple', or 'complex'."
}
}
variable "config_1" {
type = string
description = "Configuration 1"
default = null
}
variable "config_2" {
type = string
description = "Configuration 2"
default = null
}
variable "config_3" {
type = string
description = "Configuration 3"
default = null
}
locals {
scenarios = {
simple = {
config_1 = coalesce(var.config_1, "simple-config-1")
config_2 = coalesce(var.config_2, "simple-config-2")
config_3 = coalesce(var.config_3, "simple-config-3")
}
complex = {
config_1 = coalesce(var.config_1, "complex-config-1")
config_2 = coalesce(var.config_2, "complex-config-2")
config_3 = coalesce(var.config_3, "complex-config-3")
}
}
}
resource "my_resource" "this" {
config_1 = local.scenarios[var.scenario].config_1
config_2 = local.scenarios[var.scenario].config_2
config_3 = local.scenarios[var.scenario].config_3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment