你好,stackoverflow社区。
我有5个FQDN(myurl{1..5}.mydomain.com
(,每个FQDN需要创建3个Route53健康检查(总共15个(。每个FQDN后面有两个IP,例如myurl1.mydomain.com
有IP:123.123.123.123, 124.124.124.124
。最终目标:
- 对特定FQDN的每个IP进行2次运行状况检查
- 1计算健康检查,监测上述两项
第一点通过以下方式完成:
data "dns_a_record_set" "mywiz" {
for_each = toset(var.urls)
host = "${each.value}.mydomain.com"
}
resource "aws_route53_health_check" "hc-1" {
for_each = data.dns_a_record_set.sort(mywiz)
fqdn = each.value["host"]
ip_address = each.value["addrs"][0]
port = "443"
type = "HTTPS"
failure_threshold = "3"
request_interval = "30"
tags = {
"Name" = "r53-hc-gfp-${each.key}-1"
}
lifecycle {
ignore_changes = [tags]
}
}
resource "aws_route53_health_check" "hc-2" {
#count = length(var.urls)
for_each = data.dns_a_record_set.mywiz
fqdn = each.value["host"]
ip_address = each.value["addrs"][1]
port = "443"
type = "HTTPS"
failure_threshold = "3"
request_interval = "30"
tags = {
"Name" = "r53-hc-gfp-${each.key}-2"
}
lifecycle {
ignore_changes = [tags]
}
}
输出为:
# aws_route53_health_check.hc-1["myurl1"] will be created
+ resource "aws_route53_health_check" "hc-1" {
+ arn = (known after apply)
+ disabled = false
+ enable_sni = (known after apply)
+ failure_threshold = 3
+ fqdn = "myurl1.mydomain.com"
+ id = (known after apply)
+ ip_address = "123.123.123.123"
+ measure_latency = false
+ port = 443
+ request_interval = 30
+ tags = {
+ "Name" = "r53-hc-gfp-myurl1-1"
}
+ tags_all = {
+ "CreatedBy" = "foobar"
+ "CreatedDate" = "2022-03-10T07:48:05Z"
+ "LaunchSource" = "Terraform"
+ "Name" = "r53-hc-gfp-myurl1-1"
+ "Notes" = "Created for GFP"
}
+ type = "HTTPS"
}
# aws_route53_health_check.hc-2["myurl1"] will be created
+ resource "aws_route53_health_check" "hc-2" {
+ arn = (known after apply)
+ disabled = false
+ enable_sni = (known after apply)
+ failure_threshold = 3
+ fqdn = "myurl1.mydomain.com"
+ id = (known after apply)
+ ip_address = "124.124.124.124"
+ measure_latency = false
+ port = 443
+ request_interval = 30
+ tags = {
+ "Name" = "r53-hc-gfp-myurl1-2"
}
+ tags_all = {
+ "CreatedBy" = "foobar"
+ "CreatedDate" = "2022-03-10T07:48:05Z"
+ "LaunchSource" = "Terraform"
+ "Name" = "r53-hc-gfp-myurl1-2"
+ "Notes" = "Created for GFP"
}
+ type = "HTTPS"
}
然而,我正在努力与计算的Route53健康检查。如何构造CALCULATEDaws_route53_health_check
资源,如何将正确的(用于相应FQDN的(健康检查ID传递为child_healthchecks
。我尝试过:
resource "aws_route53_health_check" "hc-status" {
for_each = aws_route53_health_check.hc-1
type = "CALCULATED"
failure_threshold = "1"
child_healthchecks = [aws_route53_health_check.hc-1.id[each.key]
child_health_threshold = "1"
tags = {
"Name" = "r53-hc-gfpstatus-${each.key}"
}
lifecycle {
ignore_changes = [tags]
}
}
这导致:
|Error: Missing resource instance key
│
│ on main.tf line 58, in resource "aws_route53_health_check" "hc-status":
│ 58: child_healthchecks = [aws_route53_health_check.hc-1.id[each.key]]
│
│ Because aws_route53_health_check.hc-1 has "for_each" set, its attributes must be accessed
│ on specific instances.
│
│ For example, to correlate with indices of a referring resource, use:
│ aws_route53_health_check.hc-1[each.key]
应该是:
child_healthchecks = [aws_route53_health_check.hc-1[each.key].id]
不是
child_healthchecks = [aws_route53_health_check.hc-1.id[each.key]]