How do you upload a directory of files or enumerate files?
IntermediateConceptLoops, Conditionals, Dynamic Blocks and Functions
Answer
fileset(path, pattern) returns a set of relative file paths, which you can feed straight to for_each.
resource "aws_s3_object" "site" {
for_each = fileset("${path.module}/site", "**")
bucket = aws_s3_bucket.web.id
key = each.value
source = "${path.module}/site/${each.value}"
etag = filemd5("${path.module}/site/${each.value}")
}
More on Loops, Conditionals, Dynamic Blocks and Functions
How does `count` work?BeginnerHow does `for_each` work?BeginnerWhen should you choose `for_each` over `count`?IntermediateHow do you use `for_each` with a list of objects?IntermediateWhat does "The for_each value depends on resource attributes that cannot be determined until apply" mean?AdvancedHow do you create a resource conditionally?Beginner