terragrunt
terragrunt copied to clipboard
Set Environment variables for with before_hook script
I have a before hook that runs a shell script to refresh my GCP token.
before_hook "before_hook" {
commands = ["apply", "plan", "init", "refresh"]
execute = ["bash", "${get_parent_terragrunt_dir()}/../.scripts/gcp_auto_reauth.sh"]
}
The script checks the expire time of the current token and refreshes the token if 10 mins remain using the below commands
GOOGLE_OAUTH_ACCESS_TOKEN="$(gcloud auth print-access-token)"
export GOOGLE_OAUTH_ACCESS_TOKEN
The token gets refreshed but the GOOGLE_OAUTH_ACCESS_TOKEN environment variable isn't set within the context of the terraform command. Terraform fails with a HTTP response code 401 error while accessing state. I assume due to the shell script being executed within it's own process so the updated token is set there only.
What's the best way to overcome this issue?