首页 > 解决方案 > Terraform 文字未终止

问题描述

我定义了以下变量。

variable "pg_parameters" {
  type        = "list"
  description = "A list of parameters for configuring the parameter groups."

  default = [
    {
      name         = "rds.logical_replication"
      value        = 1
      apply_method = "pending-reboot"
    },
  ]
}

然后在我的 tf 模块中,我想在名为parameter.

  parameter = "[
    "${var.pg_parameters}",
    "{
      "name": "rds.force_ssl",
      "value": "${lookup(var.ssl, element(var.environments, count.index), 1)}",
      "apply_method": "pending-reboot"
    }",
  ]"

但相反,我收到了这个错误:

Error loading modules: module postgres_ssl_off: Error parsing .terraform/modules/5ee2f0efac9d712d26a43b2388443a7c/main.tf: At 46:17: literal not terminated

我不确定实际终止在哪里丢失?

标签: terraform

解决方案


The second element in the list is a map. You need to assign to the map using =, not :. You can also drop the " around the keys, and map itself, like so:

variable "pg_parameters" {
  type        = "list"
  description = "A list of parameters for configuring the parameter groups."

  default = [
    {
      name         = "rds.logical_replication"
      value        = 1
      apply_method = "pending-reboot"
    },
  ]
}

locals {
  my_params = [
    "${var.pg_parameters}",
    {
      name         = "rds.force_ssl"
      value        = "hello"
      apply_method = "pending-reboot"
    },
  ]
}

output "example" {
  value = "${local.my_params}"
}

Applying shows

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

example = [
    {
        apply_method = pending-reboot,
        name = rds.logical_replication,
        value = 1
    },
    {
        apply_method = pending-reboot,
        name = rds.force_ssl,
        value = hello
    }
]

推荐阅读