如何在 terraform 模板文件中附加索引号

问题描述

我正在使用 terraform 模板从 terraform 准备 ansible 清单文件。我想创建一个清单文件内容,如下所示

slave-01 ansible_host=x.x.x.x
slave-02 ansible_host=x.x.x.x

所以在这里我无法根据该资源有多少 IP 地址来附加数字 01,02...等

我正在尝试的模板文件如下

%{ for index,ip in test_slaves ~}
slave-[index] ansible_host=${ip}
%{ endfor ~}

我的资源文件是

resource "local_file" "hosts_cfg" {
  content = templatefile("${path.module}/templates/hosts.tpl",{
      test_slaves  = aws_instance.test-slaves.*.public_ip
    }
  )
  filename = "${path.module}/hosts.cfg"
}

请指导我如何处理这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)