terraform - split variable value into 2

Viewed 10249

I have a variable (var.http_proxy) that holds proxy details (ip address : port). I am setting env variable to a lambda and I have 2 variable , host and port. Now I need to use split the variable and assign proxy host and port instead of defining 2 new variables. I am using the code below and it is wrong -

environment = {
    variables = {
      proxy_host = "${split(":", var.http_proxy)[0]}"
      proxy_port = "${split(":", var.http_proxy)[1]}"
    }
  }
1 Answers

The below fix resolved this -

  proxy_host = "${element(split(":", var.http_proxy),0)}"
  proxy_port = "${element(split(":", var.http_proxy),1)}"
Related