Created
October 1, 2021 17:34
-
-
Save robzr/75c193d73dddeed7e59a542c5365d0a4 to your computer and use it in GitHub Desktop.
Terraform block to dynamically determine project name & workspace from path
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 { | |
project = reverse([ | |
for potential in [ | |
for i in range(2, length(local.project_path_segments)) : { | |
git_root = join("/", slice(local.project_path_segments, 0, i + 1)) | |
name = local.project_path_segments[i] | |
workspace = join( | |
"--", | |
slice( | |
local.project_path_segments, | |
i, | |
length(local.project_path_segments), | |
) | |
) | |
} | |
] : potential | |
if fileexists("${potential.git_root}/.git/HEAD") | |
])[0] | |
project_path_segments = split("/", abspath(path.root)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment