【问题标题】:Terraform create listTerraform 创建列表
【发布时间】:2021-03-26 23:36:27
【问题描述】:

我尝试将我的 coturn 服务器的所有浮动 ips 放入 ansible 库存中。

resource "local_file" "hosts_cfg" {
  content = templatefile("${path.module}/templates/hosts.tpl",
    {
      coturn = openstack_compute_floatingip_associate_v2.coturn[*].floating_ip
    }
  )
  filename = "../ansible/inventory/hosts.cfg"
}

错误:该对象没有名为“floating_ip”的属性。

resource "local_file" "hosts_cfg" {
  content = templatefile("${path.module}/templates/hosts.tpl",
    {
      coturn = openstack_compute_floatingip_associate_v2.coturn["coturn-1"].floating_ip
    }
  )
  filename = "../ansible/inventory/hosts.cfg"
}

有效,但仅适用于一个实例。

我的模板文件。

[coturn]
%{ for ip in coturn ~}
${ip}
%{ endfor ~}

我的 openstack_compute_floatingip_associate_v2 定义。

resource "openstack_compute_floatingip_associate_v2" "coturn" {
  for_each = var.coturn_instance_names
  floating_ip = openstack_networking_floatingip_v2.coturn[each.key].address
  instance_id = openstack_compute_instance_v2.coturn[each.key].id
}

【问题讨论】:

  • 你对openstack_compute_floatingip_associate_v2的定义是什么?
  • 您可以通过设置coturn = openstack_compute_floatingip_associate_v2.coturn 然后在模板中循环遍历地图并为每个值访问floating_ip 来解决问题。

标签: ansible terraform openstack ansible-inventory terraform-provider-openstack


【解决方案1】:

这不是我问题的答案,而是解决问题。
我目前使用的是 zigarn 中提到的这种配置。

resource "local_file" "hosts_cfg" {
  content = templatefile("${path.module}/templates/hosts.tpl",
    {
      coturn = openstack_compute_floatingip_associate_v2.coturn
    }
  )
  filename = "../ansible/inventory/hosts.ini"
}
[coturn]
%{ for instance in coturn ~}
${instance.floating_ip}
%{ endfor ~}

我还是不知道,为什么会这样(link)

kafka_processors = aws_instance.kafka_processor.*.public_ip

但这不是

coturn = openstack_compute_floatingip_associate_v2.coturn.*.floating_ip

【讨论】:

  • 在你的问题中你在哪里使用openstack_compute_floatingip_associate_v2.coturn[*].floating_ip,而不是openstack_compute_floatingip_associate_v2.coturn.*.floating_ip
  • 两种方式都试过了。可悲的是,他们都没有工作。
猜你喜欢
  • 2020-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-31
  • 2022-01-26
  • 2021-03-16
相关资源
最近更新 更多