cloudbud
cloudbud

Reputation: 3278

passing variable to terraform dynamic block v12

I am trying to use the code in this repo https://github.com/jmgreg31/terraform-aws-cloudfront/

but getting a hard time in setting the variables.

My variables.tf has this value, but somehow its not working :

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 definition in module looks like:

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

can someone help me to understand what I am doing wrong here?

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.

Upvotes: 1

Views: 872

Answers (1)

stefansundin
stefansundin

Reputation: 3044

You can't have a newline between default = and the start of the expression. Try changing your block to:

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

Upvotes: 2

Related Questions