I have multiple files under some root directory, let’s call it module/data/.
I need to upload this directory to the corresponding S3 bucket. All this works as expected with:
resource "aws_s3_bucket_object" "k8s-state" { for_each = fileset("${path.module}/data", "**/*") bucket = aws_s3_bucket.kops.bucket key = each.value source = "${path.module}/data/${each.value}" etag = filemd5("${path.module}/data/${each.value}") }
The only thing is left is that I need to loop over all files recursively and replace markers (for example !S3!) with values from variables of terraform’s module.
Similar to this, but across all files in directories/subdirectories:
replace(file(“${path.module}/launchconfigs/aws_launch_configuration_masters_user_data”), “#S3”, aws_s3_bucket.kops.bucket)
So the question in one sentence: how to loop over files and replace parts of them with variables from terraform?