I’m trying to parse a ‘short_version’ variable in locals.tf.
In the shell “echo ${TF_VAR_version:0:3} | sed ‘s/.//g’” transforms ‘1.3.0’ to ‘13’.
From variables.tf
variable "version" {
type = string
default = "1.3.0"
}
From locals.tf
locals {
short_version = ["bash", "echo $${var.version:0:3} | sed 's/\\.//g'"]
#short_version = "13"
server_install = templatefile("${path.module}/files/server_install.sh", {
proxy = var.proxy
os_version = var.os_version
short_version = local.short_version
}
)
}
From main.tf
instance_user_data = local.server_install
From server_install.sh script
dnf config-manager --enable rpm${short_version}
Setting value to “13” is fine but I need the syntax for the local variable manipulation. I’m sure there is probably a handy builtin function for this.
Error:
Call to function "templatefile" failed: modules/infrastructure/files/server_install.sh:27,42-61: Invalid template interpolation value; Cannot include the given value in a string template: string required., and 1 other diagnostic(s).