我正在尝试下面的一个例子
resource "google_logging_metric" "my_metric" {
description = "Check for logs of some cron job\t"
name = "mycj-logs"
filter = "resource.type=\"k8s_container\" AND resource.labels.cluster_name=\"${local.k8s_name}\" AND resource.labels.namespace_name=\"workable\" AND resource.labels.container_name=\"mycontainer-cronjob\" \nresource.labels.pod_name:\"my-pod\""
project = "${data.terraform_remote_state.gke_k8s_env.project_id}"
metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法使过滤器字段多行?
If it's a matter of formatting the output, this answer covers it.
If you want to make your code more readable, i.e. split the long string into multiple clauses with a common separator, I've found join()
useful:
resource "google_logging_metric" "my_metric" {
description = "Check for logs of some cron job\t"
name = "mycj-logs"
project = "${data.terraform_remote_state.gke_k8s_env.project_id}"
filter = join(" AND ",
[
"resource.type=\"k8s_container\"",
"resource.labels.cluster_name=\"${local.k8s_name}\"",
"resource.labels.namespace_name=\"workable\"",
"resource.labels.container_name=\"mycontainer-cronjob\"",
"resource.labels.pod_name:\"my-pod\""
]
)
metric_descriptor {
metric_kind = "DELTA"
value_type = "INT64"
}
}
Run Code Online (Sandbox Code Playgroud)
Note that setting out the code this way shows that in the OP there may (or may not) be a missing AND in the filter
expression, between the last and second last clauses.
Because the original expression is one long line, this is very hard to see and slow to read/maintain. With the join expression the intent is clearer I think.
在 Google 中快速搜索即可找到文档:https://www.terraform.io/docs/language/expressions/strings.html#heredoc-strings
你只需要写一些类似的东西
<<EOT
hello
world
EOT
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17126 次 |
最近记录: |