5

How can I assign terraform output to environment variable?

Let's say I have following output defined in my main.tf

output "gce_public_ip" {
    value = element(concat(google_compute_instance.vm_instance.*.network_interface.0.access_config.0.nat_ip, list("")), 0)
}

I would like to export gce_public_ip, so it will be available as environment variable GCE_PUBLIC_IP

1 Answer 1

8

You can use the terraform output command.

Not tested with your value, but it should be something like:

export GCE_PUBLIC_IP=$(terraform output -raw gce_public_ip)
Sign up to request clarification or add additional context in comments.

1 Comment

You probably want to include the -raw arg on the output command i.e. export GCE_PUBLIC_IP=$(terraform output -raw gce_public_ip)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.