Created
February 9, 2023 19:48
-
-
Save tyhawkins/f21383e1e9ccdad738404d94e1627f4e to your computer and use it in GitHub Desktop.
Add git info to Terraform tags
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
data "external" "gitrepo" { | |
program = [ | |
"bash", | |
"-c", | |
<<-EOF | |
echo "{ \ | |
\"branch\":\"$(git rev-parse --abbrev-ref HEAD)\", \ | |
\"sha\":\"$(git rev-parse --short=8 HEAD)\", \ | |
\"url\":\"$(git remote get-url origin)\" \ | |
}" | |
EOF | |
] | |
} | |
locals { | |
common_tags = { | |
terraform = "true" | |
env = "dev" | |
app_name = "your-app-here" | |
repository = data.external.gitrepo.result.url | |
branch = data.external.gitrepo.result.branch | |
sha = data.external.gitrepo.result.sha | |
created_by = "DevOps" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment