'Terraform - creating multiple buckets

Creating a bucket is pretty simple.

resource "aws_s3_bucket" "henrys_bucket" {
  bucket                  = "${var.s3_bucket_name}"
  acl                     = "private"
  force_destroy           = "true"
}

Initially I thought I could create a list for the s3_bucket_name variable but I get an error:

Error: bucket must be a single value, not a list

-

variable "s3_bucket_name" {
  type = "list"
  default  = ["prod_bucket", "stage-bucket", "qa_bucket"]
}

How can I create multiple buckets without duplicating code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source