Terraform仍在尝试解决计数为零的资源中的插值问题

时间:2017-05-16 17:32:03

标签: dns terraform

我正在尝试为服务器部署创建PTR记录。在应用一组相关服务器之后,需要部署下面的服务器,因此我们目前通过运行一个应用部署这些服务器模块然后再进行第二次部署来执行此操作,其中我们将这些资源计数从0更改为我们的许多数据。重新部署。我添加了一个新资源来为这些服务器创建PTR记录,即使计数设置为0,Terraform也会尝试解析插值。对于A记录资源,它不会仅仅为PTR记录资源执行此操作。

这是代码,我甚至将计数硬编码为0以查看变量是否存在问题。当计数为0时,列表预计为空。我希望Terraform不会尝试解决插值问题。

resource "aws_route53_record" "ds_sync_A_records" {
  // same number of records as instances
  provider = "aws.dns"
  count = 0
  // count = "${var.ping_sync_cluster_count}"
  zone_id = "${data.aws_route53_zone.zone_company_io.zone_id}"
  name = "ping-sync-0${count.index}.${var.domain_name}"
  type = "A"
  ttl = "10"
  // matches up record N to instance N
  records = ["${element(module.ping_sync_hot_server.private_server_ips, count.index)}"]
}

resource "aws_route53_record" "ds_sync_PTR_records" {
  // same number of records as instances
  provider = "aws.dns"
  count = 0
  // count = "${var.ping_sync_cluster_count}"
  zone_id = "${data.aws_route53_zone.zone_company_io.zone_id}"
  name = "${format(
    "%s.%s.%s.$s.in-appr.arpa",
    element(split(".", element(module.ping_sync_hot_server.private_server_ips, count.index)), 3), 
    element(split(".", element(module.ping_sync_hot_server.private_server_ips, count.index)), 2),
    element(split(".", element(module.ping_sync_hot_server.private_server_ips, count.index)), 1), 
    element(split(".", element(module.ping_sync_hot_server.private_server_ips, count.index)), 0) 
  )}"
  type = "PTR"
  ttl = "10"
  // matches up record N to instance N
  records = ["${element(module.ping_sync_hot_server.private_server_ips, count.index)}"]
}

申请时出现错误消息:

Error running plan: 3 error(s) occurred:

* element: element() may not be used with an empty list in:

${element(module.ping_sync_hot_server.private_server_ips, count.index)}
* element: element() may not be used with an empty list in:

${element(module.ping_sync_hot_server.private_server_ips, count.index)}
* element: element() may not be used with an empty list in:

${element(module.ping_sync_hot_server.private_server_ips, count.index)}

1 个答案:

答案 0 :(得分:2)

当返回的记录是列表时,使用splat语法(*)。

records = [
  "${element(module.ping_sync_hot_server.*.private_server_ips, count.index)}",
]