过滤地形中的对象以在gcp中创建度量



我正在做这样的事情(向gcp监控添加图表(

data "template_file" "templatefileone" {
template = file("${path.module}/templatefileone.json.tmpl")
count    = length(var.one)
vars = {
title           = var.metrics[count.index][0]
metricName      = var.metrics[count.index][3]
endpoint        = var.metrics[count.index][2]
environmentName = "#ENVIRONMENT"
applicationName = var.appName
clusterName     = "#CLUSTERNAME"
envName         = var.envName
}
}
data "template_file" "templatefiletwo" {
template = file("${path.module}/templatefiletwo.json.tmpl")
count    = length(var.two)
vars = {
title           = var.jvmMetrics[count.index][0]
metricName      = var.jvmMetrics[count.index][1]
environmentName = "#ENVIRONMENT"
applicationName = var.appName
clusterName     = "#CLUSTERNAME"
envName         = var.envName
}
}
resource "google_monitoring_dashboard" "dashboard" {
for_each = local.environmentsLabels
dashboard_json = templatefile("${path.module}/dashboard.json.tmpl", {
app_name = var.appName,
env_name = each.key,
widgets  = join(",",
[for metric in sort(concat(
data.template_file.templatefileone.*.rendered,
[for xyz in data.template_file.templatefiletwo: xyz if (try(sm.vars.endpoint, "") != "")].*.rendered
)) : doSomethingThatDoesntMatterHere()]
)
})
project = var.projectId
}

我正在尝试通过图表"templatefiletwo"进行筛选,这样只有那些在变量"endpoint"中有内容的图表才会加入到"widgets"变量中。目前它看起来像:

widgets  = join(",",
[for metric in sort(concat(
data.template_file.templatefileone.*.rendered,
data.template_file.templatefiletwo.*.rendered
)) : doSomethingThatDoesntMatterHere()]
)

我期待

[for xyz in data.template_file.templatefiletwo: xyz if (try(sm.vars.endpoint, "") != "")]

只返回和data.template_file.templatefiletwo相同的东西,这样我就可以调用它上的.*.render,但显然它不是这样工作的。

花了半天时间,我决定把它推到环境中,看看它给我发来的错误。看起来我的代码一直都像预期的那样完美地工作,只是IDEA的terrafrom插件无法处理它,并认为这是一个错误。我不会删除这个问题,因为这可能会为某人节省很多时间。