Assign terraform output to environment variable

Viewed 1460

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 Answers

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)
Related