Home > Blockchain >  Terraform: Use variable list type for aws Cloudfront resource
Terraform: Use variable list type for aws Cloudfront resource

Time:06-03

I'm having trouble using a list type variable in an AWS Cloudfront resource for the 'alias' argument.

variables.tf

variable "my_domains" {
  type = list(string)
  default = ["one.domain.tld", "two.domain.tld"]
}

distribution.tf

resource "aws_cloudfront_distribution" "my_domain_com" {
  ...
  aliases = [var.my_domains]
  ...
}

This presents an error:

var.my_domains is list of string with 2 elements. Cannot include the given value in a string template: string required.

CodePudding user response:

It should be aliases and my_domains is already a list:

resource "aws_cloudfront_distribution" "my_domain_com" {
  ...
  aliases = var.my_domains
  ...
}
  • Related