Terraform文字未终止

时间:2018-09-04 22:15:43

标签: 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

我不确定实际终止的位置在哪里?

1 个答案:

答案 0 :(得分:2)

列表中的第二个元素是地图。您需要使用=而非:分配给地图。您还可以将"放到键周围,并映射自身,如下所示:

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

应用节目

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