Terraform插值-将字符串转换为列表

时间:2019-03-01 12:52:28

标签: terraform string-interpolation

如何将字符串"foo, bar, xid, uid"转换为列表["foo", "bar", "xid", "uid"]

我要从Consul分配变量值,它是一个字符串

my_var = "foo, bar, xid, uid"

现在,我想将my_var转换为如下所示的列表:

my_list = ["foo", "bar", "xid", uid"]

我该如何实现?我试图为此使用formatlist和splat运算符,但没有成功

my_list = ${formatlist(<put magic here>, var.my_var)

2 个答案:

答案 0 :(得分:1)

您可以在此处使用split function

my_list = ${split(",", var.my_var)}

答案 1 :(得分:0)

ydaetskcoR的答案本质上是正确的,但在Terraform 0.12 中,语法已更改,并且拆分功能行应显示为:

Current ip is: 
199.229.249.163
Your true ip is: 
199.229.249.163



testing proxies...



proxy: 104.236.54.196:8080
Current ip is: 
199.229.249.163
Your true ip is: 
199.229.249.163



Proxy failed.


proxy: 187.62.191.3:61456
Current ip is: 
199.229.249.163
Your true ip is: 
199.229.249.163



Proxy failed.


proxy: 138.204.179.162:44088
Current ip is: 
199.229.249.163
Your true ip is: 
199.229.249.163



Proxy failed.


proxy: 91.216.66.70:32306
Current ip is: 
199.229.249.163
Your true ip is: 
199.229.249.163



Proxy failed.