Terraform-在渲染时将变量传递给模板文件吗?

时间:2019-01-08 21:18:41

标签: terraform terraform-template-file hcl

在Terraform / HCL中,是否存在在渲染时将变量传递到模板的方法,还是基于Null资源的触发来引用变量的方法?

我目前正在使用这样的Null资源:

resource "null_resource" "foo" {
    count = "${var.node_count}"  
    triggers {
        instance_ids = "${element(openstack_compute_instance_v2.nodes.*.id, count.index)}"
}


provisioner "local-exec" {
    command = "foo ${element(openstack_compute_instance_v2.nodes.*.id, count.index)} bar ${element(openstack_networking_floatingip_v2.floating_ips.*.address, count.index)}"

但是我想将命令移到模板中(我将其用于几种不同类型的节点),并执行以下操作:

data "template_file" "foo" {
    template = "${file("${path.module}/templates/foo.tpl")}"
    vars {
        floating_ip = "${some kind of reference to the null resource instance that was triggered.floating_ips.address}"
        instance_id = "${some kind of reference to the null resource instance that was triggered.floating_ips.address}"
    }
}
resource "null_resource" "bar" {
    count = "${var.node_count}"  
    triggers {
        instance_ids = "${element(openstack_compute_instance_v2.nodes.*.id, count.index)}"
        floating_ip_ids = "${element(openstack_networking_floatingip_v2.floating_ips.*.address, count.index)}"
    }
}

provisioner "local-exec" {
    command = "${data.template_file.ingress_allowed_address.rendered}"

我似乎找不到找到引用触发模板文件中空资源的特定实例的方法,或直接将其传递给模板数据源的方法。

有什么建议吗?

0 个答案:

没有答案