Created
April 23, 2024 19:16
-
-
Save tedivm/76f64e6e9b711ffd715e6ef49e95eafc to your computer and use it in GitHub Desktop.
Terraform Module Version from Inside Module
This file contains 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 { | |
# Load the module versions from the modules.json file. | |
module_versions = jsondecode(file("${path.root}/.terraform/modules/modules.json")) | |
# Convert the module versions data into an object, | |
# with the module source path as key and version as value. | |
modules_by_source = { for module in local.module_versions : | |
module["Source"] => try(module["Version"], null) | |
} | |
# Pluck the version from the module object using the path to the module. | |
# The path.module is the same as the module source. | |
version = local.modules_by_source[path.module] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment