【问题标题】:Terraform still trying to resolve interpolation in resource with count of zeroTerraform 仍在尝试解决资源中的插值问题,计数为零
【发布时间】:2018-01-31 18:03:51
【问题描述】:

我正在尝试为服务器部署创建 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)}

【问题讨论】:

    标签: dns terraform


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 2022-08-16
      • 2018-09-24
      • 2012-01-24
      • 2021-01-05
      相关资源
      最近更新 更多