Tag variable with list in aws_s3_bucket terraform resource

Viewed 21

I am trying to create a tag variable as part of a module for aws_s3_bucket terraform resource. One of the tag keys should allow a list(string) value. What data type should I use?

I tried the following in variables.tf:

variable "name" {
  type        = string
}

variable "tags" {
  type = object({
    Owner        = string
    DataCategory = list(string)
  }))

With this implementation in main.tf:

resource "aws_s3_bucket" "bucket" {
  bucket = var.name
  tags = var.tags
}

And trying to create a bucket in ./example/main.tf:

module "s3_bucket_test" {
  source        = "../"
  name          = "example-bucket"
  tags = {
    Owner        = "My Team"
    DataCategory = ["Customer","Finance"]

  }
}

But I am getting the error:

Inappropriate value for attribute "tags": element "DataCategory": string required.

0 Answers
Related