aas*_*yas 1 amazon-route53 terraform terraform0.12+
我正在为字符串变量的给定值中的每个服务创建一个route53运行状况检查services。
tfvars当我传递 services 变量的值时,我的文件如下所示
services = "servicea serviceb serviced"
我只需要进行这些健康检查,如果var.env == prod。
有一种经过尝试和测试的方法可以使用,并且将会使用,count = var.env == prod ? 1:0但由于我已经使用 count 来计算和迭代服务字符串,我无法count在同一资源块中再次使用,因为 terraform 0.12 给了我以下错误如果我想这样做,请留言。
在同一资源块中使用多个计数时出错
Error: Attribute redefined
on <stdin> line 514: (source code not available)
The argument "count" was already set at <stdin>:513,2-7. Each argument may be set only once.
Run Code Online (Sandbox Code Playgroud)
地形配置
variable "services" {
default = ""
}
resource aws_route53_health_check "app_healthcheck" {
count = length(split(",", replace(var.services, "/\\s/", ",")))
fqdn = "${var.super_cluster}-${var.region}.domainname.com"
port = 443
type = "HTTPS"
resource_path = "/canSchedule?appName=${element(split(",", replace(var.services, "/\\s/", ",")), count.index)}"
request_interval = "10"
failure_threshold = "1"
enable_sni = true
tags = local.common_tags
}
Run Code Online (Sandbox Code Playgroud)
count一旦在资源块中使用,如何创建条件资源?
要解决此问题,您可以引入一个新的 local 来检查 env 变量的值:
locals {
is_prod = var.env == "prod" ? true : false
}
Run Code Online (Sandbox Code Playgroud)
然后在您的资源块中在条件表达式中使用该本地变量,如下所示:
count = local.is_prod ? length(split(",", replace(var.services, "/\\s/", ","))) : 0
| 归档时间: |
|
| 查看次数: |
11172 次 |
| 最近记录: |