How can I extract parts of a variable in

I’m trying to parse a ‘short_version’ variable in

In the shell “echo ${TF_VAR_version:0:3} | sed ‘s/.//g’” transforms ‘1.3.0’ to ‘13’.


variable "version" {
  type        = string
  default     = "1.3.0"


locals {
        short_version = ["bash", "echo $${var.version:0:3} | sed 's/\\.//g'"]
        #short_version = "13"

        server_install = templatefile("${path.module}/files/", {
                proxy           = var.proxy
                os_version      = var.os_version
                short_version   = local.short_version


instance_user_data = local.server_install

From 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.


Call to function "templatefile" failed: modules/infrastructure/files/,42-61: Invalid template interpolation value; Cannot include the given value in a string template: string required., and 1 other diagnostic(s).

Sorted. I didn’t delete the question as it may help someone.

> join("", [element(split("", var.version), 0),element(split("", var.version), 2)])