Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terraform - split variable value into 2

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]}"
    }
  }
like image 701
Punter Vicky Avatar asked Sep 04 '26 04:09

Punter Vicky


1 Answers

The below fix resolved this -

  proxy_host = "${element(split(":", var.http_proxy),0)}"
  proxy_port = "${element(split(":", var.http_proxy),1)}"
like image 185
Punter Vicky Avatar answered Sep 07 '26 15:09

Punter Vicky