Last active
January 31, 2022 13:00
-
-
Save yamatt/04688c19d29af7cd340bb45a23534f66 to your computer and use it in GitHub Desktop.
Iterate over files in directory and parse in a Terraform module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"))] | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output "contents" { | |
value = local.contents | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment