How do I save the output variable from terragrunt apply as regular shell environment variable?

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-output

I 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.

3

You will need to expand the command and so:

export HOSTNAME="$(terragrunt apply-all | awk -F= '/value/ { gsub(" ","",$2);print $2 }')"
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like