Anyone know if there's a way to populate variables in Terraform based on what the environment/workspace is? Preferably one that
tf(){ terraform --var-file=$(get_tf_env).tfvars
terraform env
)? Populates the var namespace, doesn't require a wrapper, and takes effect by changing the workspace (Terraform 0.12 code):
variable "ami_id" {
type = map(string)
default = {
stg = "ami-foo28929"
prd = "ami-bar39b12"
}
}
resource "aws_instance" "this" {
ami = var.ami_id[terraform.workspace]
(...)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With