Created
October 20, 2023 08:23
-
-
Save matt-FFFFFF/c6454f2c1f60fbc5ccc75b22187ac203 to your computer and use it in GitHub Desktop.
Scenario selection with tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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