<p>On your command line, run <code>printenv</code></p>
<p>Reference: <a href="https://man7.org/linux/man-pages/man1/printenv.1.html" rel="nofollow noreferrer">https://man7.org/linux/man-pages/man1/printenv.1.html</a></p>

CC BY-SA 4.0
2020-07-29T03:53:29.347Z
Indeed, running `printenv` returns system environment variables but I don't recognize any of them to be Terraform variables, such as the mentioned access key ID and secret access key. Any suggestions on how to run a similar command under Terraform's context?
randvir
CC BY-SA 4.0
2020-07-29T16:02:18.643Z
@randvir Terraform uses that same "context". https://www.terraform.io/docs/commands/environment-variables.html
Woodland
CC BY-SA 4.0
2020-08-08T11:29:44.150Z
I found out my question is flawed. I discovered that I configured the AWS CLI to store credentials inside the AWS credentials file, not inside environment variables. Your answer helped me realize I'm looking in the wrong place and also taught me how to view environment variables. Thanks.
randvir
CC BY-SA 4.0
2020-07-27T16:11:28.797Z
2020-07-27T16:11:28.797Z
Woodland
<p>Your current shell environment variables, which are also including terraform-related ones can be listed by <code>env</code> command or you can do it in tf file:</p>
<pre><code>terraform {
  required_version = &quot;&gt;= 0.12.0&quot;
}

resource &quot;null_resource&quot; &quot;get_tf_env&quot; {
  provisioner &quot;local-exec&quot; {
    command = &quot;env&quot;
    interpreter = [&quot;bash&quot;, &quot;-c&quot;]
  }
}
</code></pre>
<p>According to <a href="https://www.terraform.io/docs/commands/environment-variables.html" rel="nofollow noreferrer">official docs</a> you can only feed terraform with the envs starting with <code>TF_*</code>.</p>

CC BY-SA 4.0
2020-07-29T22:13:48.997Z
2020-07-29T22:13:48.997Z
Hakob
<p><code>printenv | grep TF_VAR</code> will list all variables that you defined.</p>

CC BY-SA 4.0
2021-05-09T18:46:40.420Z
2021-05-10T04:56:33.580Z
2021-05-10T04:56:33.580Z
Naveen Kumar
<p>I configured AWS provider in Terraform by providing an access key and secret as environment variables according to the <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs" rel="nofollow noreferrer">documentation</a>:</p>
<p><code>$ export AWS_ACCESS_KEY_ID=&quot;anaccesskey&quot;</code> <br />
<code>$ export AWS_SECRET_ACCESS_KEY=&quot;asecretkey&quot;</code></p>
<p>I now want to view those variables on the console as well as other environment variables configured on my system but I can't find the right command.</p>
<p><strong>Update:</strong> I found out that I didn't configure the AWS provider like I thought. The AWS CLI was already configured with my credentials stored in <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html" rel="nofollow noreferrer">AWS credentials file</a>: <code>~/.aws/credentials</code>.</p>

<amazon-web-services><terraform>
How can I list all environment variables configured in Terraform?
randvir
# How can I list all environment variables configured in Terraform?

(Asked by: username_0 on 2020-07-25)

I configured AWS provider in Terraform by providing an access key and secret as environment variables according to the [documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs):

`$ export AWS_ACCESS_KEY_ID="anaccesskey"`   
`$ export AWS_SECRET_ACCESS_KEY="asecretkey"`

I now want to view those variables on the console as well as other environment variables configured on my system but I can't find the right command.

**Update:** I found out that I didn't configure the AWS provider like I thought. The AWS CLI was already configured with my credentials stored in [AWS credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html): `~/.aws/credentials`.

**Tags:** amazon-web-services, terraform


---

## 3 answers

### Answer by username_1 on 2020-07-27. Score: 1 | Accepted answer

On your command line, run `printenv`

Reference: <https://man7.org/linux/man-pages/man1/printenv.1.html>

> **Comments:**
> **username_0**: Indeed, running `printenv` returns system environment variables but I don't recognize any of them to be Terraform variables, such as the mentioned access key ID and secret access key. Any suggestions on how to run a similar command under Terraform's context?  
> **username_1**: @username_0 Terraform uses that same "context". https://www.terraform.io/docs/commands/environment-variables.html  
> **username_0**: I found out my question is flawed. I discovered that I configured the AWS CLI to store credentials inside the AWS credentials file, not inside environment variables. Your answer helped me realize I'm looking in the wrong place and also taught me how to view environment variables. Thanks.  

---

### Answer by username_2 on 2020-07-29. Score: 1

Your current shell environment variables, which are also including terraform-related ones can be listed by env command or you can do it in tf file:
terraform {
  required_version = ">= 0.12.0"
}

resource "null_resource" "get_tf_env" {
  provisioner "local-exec" {
    command = "env"
    interpreter = ["bash", "-c"]
  }
}

According to official docs you can only feed terraform with the envs starting with TF_*.


---

### Answer by username_3 on 2021-05-09. Score: 1

`printenv | grep TF_VAR` will list all variables that you defined.


---

