Skip to content

Instantly share code, notes, and snippets.

@yamatt
Last active January 31, 2022 13:00
Show Gist options
  • Save yamatt/04688c19d29af7cd340bb45a23534f66 to your computer and use it in GitHub Desktop.
Save yamatt/04688c19d29af7cd340bb45a23534f66 to your computer and use it in GitHub Desktop.
Iterate over files in directory and parse in a Terraform module
locals {
base_path = "${path.module}/files"
yaml_files = fileset(local.base_path, "**.yml")
contents = zipmap(
[for file_path in local.yaml_files : trimsuffix(basename(file_path), ".yml")],
[for file_path in local.yaml_files : yamldecode(file("${local.base_path}/${file_path}"))]
)
}
output "contents" {
value = local.contents
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment