How do I save the output variable from terragrunt apply as regular shell environment variable?
Andrew Henderson
After running my terragrunt apply-all in my CI step (so basically a bash script) I get my outputs, in this case I only have one:
output "cloudrun-hostname" { value = google_cloud_run_service.cloudrun.status[0].url description = "API endpoint URL"
}How do I pass the value of that output to the environment variable so basically like I exported a variable like this:
export HOSTNAME=terragrunt-cloudrun-hostname-outputI need this variable with that value so I can envsub the value in another file later.
2 Answers
You can use the terraform output command, i.e.
export MY_ENV=$(terraform output cloudrun-hostname)after your apply-all.
You will need to expand the command and so:
export HOSTNAME="$(terragrunt apply-all | awk -F= '/value/ { gsub(" ","",$2);print $2 }')" 4