Create multile files using local_file resource type

Hello…i’m new to Terraform and here is what i’m trying to do…Kindly help

How to create multile files using local_file resource type under single resource block and this has to be variabalised. I tried doing, but it did not work…

Main.tf
resource “local_file” “foo” {
content = var.content
filename = for_each(var.filename)
}

Variable.tf
variable “filename” {
default = [“/root/foo.txt”,“/root/foo1.txt”,“/root/foo2.txt”]
type = list(string)
}
variable “content” {
default = “Testing the script”

Hello Zafar03,

try this:

Main.tf
resource “local_file” “foo” {
content = var.content
for_each= toset(var.filename)
filename = each.key
}

Variable.tf
variable “filename” {
default = [“/root/foo.txt”,“/root/foo1.txt”,“/root/foo2.txt”]
type = list(string)
}
variable “content” {
default = “Testing the script”
}

Thanks,
KodeKloud Support