Skip to content

Instantly share code, notes, and snippets.

@tedivm
Created April 23, 2024 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedivm/76f64e6e9b711ffd715e6ef49e95eafc to your computer and use it in GitHub Desktop.
Save tedivm/76f64e6e9b711ffd715e6ef49e95eafc to your computer and use it in GitHub Desktop.
Terraform Module Version from Inside Module
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