This will return the full Git commit SHA of whichever branch is currently checkedout.
Dump the snippet into terraform console
(run from within a Git repo) to see for yourself.
trimspace(file(".git/${trimspace(trimprefix(file(".git/HEAD"), "ref:"))}")) |
If you are using Terraform Cloud or Terraform Enterprise you can use the
TFC_CONFIGURATION_VERSION_GIT_COMMIT_SHA
environment variable.and reference it as
vars.TFC_CONFIGURATION_VERSION_GIT_COMMIT_SHA
https://developer.hashicorp.com/terraform/cloud-docs/run/run-environment#environment-variables