For example, In variable.tf file we have a code like below
variable "variable1" {
type = string
default = "ABC"
}
variable "variable2" {
type = string
default = "DEF"
}
variable "variable3" {
type = string
default = "$var.variable1-$var.variable2"
}
Expected output :
variable3 = ABC-DEF
you can use local
instead
locals {
variable3 = var.variable1+"-"+var.variable2
}
and then to call it instead of using var.
use local.
like this!
resource "example" "example" {
example = local.variable3
}
ref : https://www.terraform.io/docs/configuration/locals.html
Yes, I agree with @Montassar, you can use the local
block to create a new expression from the existing resources or the variables. But it should combine the variables like this:
locals {
variable3 = "${var.variable1}-${var.variable2}"
}
And it will look like this:
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