将变量传递给 terraform 动态块 v12

passing variable to terraform dynamic block v12

我正在尝试使用此存储库中的代码 https://github.com/jmgreg31/terraform-aws-cloudfront/

但是在设置变量时遇到困难。

我的 variables.tf 有这个值,但不知何故它不起作用:

variable "dynamic_s3_origin_config" {
default =
[
  {
    domain_name            = "domain.s3.amazonaws.com"
    origin_id              = "S3-domain-cert"
    origin_access_identity = "origin-access-identity/cloudfront/1234"
  },
  {
    domain_name            = "domain2.s3.amazonaws.com"
    origin_id              = "S3-domain2-cert"
    origin_access_identity = "origin-access-identity/cloudfront/1234"
    origin_path            = ""
  }
]

}

模块中的变量定义如下:

variable dynamic_s3_origin_config {
  description = "Configuration for the s3 origin config to be used in dynamic block"
  type        = list(map(string))
  default     = []
}

有人可以帮助我了解我在这里做错了什么吗?

terraform plan

Error: Invalid expression

  on variables.tf line 65, in variable "dynamic_s3_origin_config":
  65:
  66:

Expected the start of an expression, but found an invalid expression token.

default = 和表达式开头之间不能有换行符。尝试将您的块更改为:

variable "dynamic_s3_origin_config" {
  default = [
    {
      domain_name            = "domain.s3.amazonaws.com"
      origin_id              = "S3-domain-cert"
      origin_access_identity = "origin-access-identity/cloudfront/1234"
    },
    {
      domain_name            = "domain2.s3.amazonaws.com"
      origin_id              = "S3-domain2-cert"
      origin_access_identity = "origin-access-identity/cloudfront/1234"
      origin_path            = ""
    }
  ]
}