无法计算Terraform的“计数”值:为什么?

时间:2019-01-10 13:12:51

标签: terraform

我的模板中具有以下资源规范:

resource "azurerm_sql_firewall_rule" "allow_app_server" {
  count = "${length(split(",", azurerm_app_service.backend.outbound_ip_addresses))}"

  depends_on = ["azurerm_app_service.backend"]

  name                = "${format("Allow App Service Plan %d", count.index)}"
  start_ip_address    = "${element(split(",", azurerm_app_service.backend.possible_outbound_ip_addresses), count.index)}"
  end_ip_address      = "${element(split(",", azurerm_app_service.backend.possible_outbound_ip_addresses), count.index)}"
  resource_group_name = "${var.environment_resource_group_name}"
  server_name         = "${var.db_server_name}"
}

resource "azurerm_app_service" "backend" {
   # properties ommitted for brevity
}

现在,当我运行terraform plan时,消息错误

  

azurerm_sql_firewall_rule.allow_app_server:无法计算“ count”的值

为什么?我该怎么做才能解决此问题(不需要我部分部署模板)?

2 个答案:

答案 0 :(得分:2)

您有双引号问题,请尝试以下操作:

wrap_content

答案 1 :(得分:0)

您是否尝试用方括号包裹?

resource "azurerm_sql_firewall_rule" "allow_app_server" {
  count = "${length([split(",", azurerm_app_service.backend.outbound_ip_addresses)])}"

  depends_on = ["azurerm_app_service.backend"]

  name                = "${format("Allow App Service Plan %d", count.index)}"
  start_ip_address    = "${element(split(",", azurerm_app_service.backend.possible_outbound_ip_addresses), count.index)}"
  end_ip_address      = "${element(split(",", azurerm_app_service.backend.possible_outbound_ip_addresses), count.index)}"
  resource_group_name = "${var.environment_resource_group_name}"
  server_name         = "${var.db_server_name}"
}

resource "azurerm_app_service" "backend" {
   # properties ommitted for brevity
}
`