How can I use environment variable in output?

Now I am using terraform cloud.
I can set environment variables in workspace variables UI.
For example, I set AWS_REGIOIN environment variable.
I want to use this in output like;

output "aws-region" {
  value     = "${AWS_REGION}"
}

so from the other module, can use this.
Is this possible?

You’ll need to pass the data into Terraform by means of a variable – first you’d need to have that variable declared:

variable "aws_region" {}

And then you’d be able to have an environment variable with the prefix TF_VAR_ for Terraform to read it: Input Variables - Configuration Language - Terraform by HashiCorp

You’d then reference that in your output by:

output "aws_region" {
  value = var.aws_region
}
1 Like