使 Terraform 资源键多行

Make Terraform resource key multiline

我正在 Terraform 中声明一个 google_logging_metric 资源(使用版本 0.11.14

我有以下声明

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"
  }
}

有没有办法让 filter 字段多行?

local 变量 "${local.k8s_name} 的存在使其具有挑战性。

来自the docs

String values are simple and represent a basic key to value mapping where the key is the variable name. An example is:

variable "key" {
  type    = "string"
  default = "value"
}

A multi-line string value can be provided using heredoc syntax.

variable "long_key" {
  type = "string"
  default = <<EOF
This is a long key.
Running over several lines.
EOF
}