<p>You can find the keys with</p>
<pre class="lang-sh prettyprint-override"><code>terraform show -json |
  jq '.values[].resources[] | select(.address==&quot;data.local_sensitive_file.public_key&quot;).values | keys'
</code></pre>
<p>Which should return,</p>
<pre class="lang-json prettyprint-override"><code>[
  &quot;content&quot;,
  &quot;content_base64&quot;,
  &quot;filename&quot;,
  &quot;id&quot;
]
</code></pre>
<p>Alternatively you can look up <a href="https://registry.terraform.io/providers/hashicorp/local/latest/docs/data-sources/sensitive_file" rel="nofollow noreferrer"><code>local_sensitive_file</code></a> in the docs.</p>

CC BY-SA 4.0
2023-06-23T19:02:40.917Z
It doesn't work: first item is null. Try it yourself!
EnzoR
CC BY-SA 4.0
2023-02-14T20:34:01.580Z
2023-02-14T20:34:01.580Z
Evan Carroll
<p>Since <code>local_sensitive_file</code> here is a data source, you can assume that its attributes are the attributes defined by the provider that this data source belongs to, which is <a href="https://registry.terraform.io/providers/hashicorp/local/latest/docs" rel="nofollow noreferrer"><code>hashicorp/local</code></a>.</p>
<p>At the time of writing <a href="https://registry.terraform.io/providers/hashicorp/local/latest/docs/data-sources/sensitive_file" rel="nofollow noreferrer">the documentation for <code>local_sensitive_file</code></a> says that it has the following attributes:</p>
<ul>
<li><code>filename</code></li>
<li><code>content</code></li>
<li><code>content_base64</code></li>
<li><code>id</code></li>
</ul>
<p>Provider documentation is typically the best place to find out about attributes of a resource type because it'll also tell you what these attributes represent, in addition to their names.</p>
<p>Not all objects you'll encounter in Terraform will originate in providers though, so a more general answer that will work for any object you can refer to in an expression is to run <code>terraform console</code> and then ask it for the type of the value in question:</p>
<pre><code>&gt; type(data.local_sensitive_file.public_key)
object({
    content: string,
    content_base64: string,
    filename: string,
    id: string,
})
</code></pre>
<p>Unfortunately for a resource (either a <code>resource</code> or <code>data</code> block) it won't yet have a known type until it's been created or read for the first time, and so if your configuration isn't valid then you would need to make it valid enough to run <code>terraform apply</code> successfully before you could use this technique. But for objects that are defined within the Terraform configuration itself, rather than by external operations that haven't run yet, the console is a useful way to inspect data and data types.</p>

CC BY-SA 4.0
2023-02-15T16:21:54.350Z
your answer is better than mine, thanks for coming in after with it.
Evan Carroll
CC BY-SA 4.0
2023-02-15T02:10:47.643Z
2023-02-15T02:10:47.643Z
Martin Atkins
<p>I'm creating a Terraform file, and something is obviously wrong,</p>
<pre><code>Error: Incorrect condition type

  on ssh.tf line 47, in locals:
  47:   is_generated = data.local_sensitive_file.public_key ? true : false
    ├────────────────
    │ data.local_sensitive_file.public_key is object with 4 attributes

The condition expression must be of type bool.
</code></pre>
<p>How do I find out what the attributes of <code>data.local_sensitive_file.public_key</code> are though?</p>

<terraform>
How do I find out the attributes of a terraform object?
Evan Carroll
# How do I find out the attributes of a terraform object?

(Asked by: username_0 on 2023-02-14)

I'm creating a Terraform file, and something is obviously wrong,
Error: Incorrect condition type

  on ssh.tf line 47, in locals:
  47:   is_generated = data.local_sensitive_file.public_key ? true : false
    ├────────────────
    │ data.local_sensitive_file.public_key is object with 4 attributes

The condition expression must be of type bool.

How do I find out what the attributes of data.local_sensitive_file.public_key are though?

**Tags:** terraform


---

## 2 answers

### Answer by username_2 on 2023-02-15. Score: 4 | Accepted answer

Since local_sensitive_file here is a data source, you can assume that its attributes are the attributes defined by the provider that this data source belongs to, which is hashicorp/local.
At the time of writing the documentation for local_sensitive_file says that it has the following attributes:

filename
content
content_base64
id

Provider documentation is typically the best place to find out about attributes of a resource type because it'll also tell you what these attributes represent, in addition to their names.
Not all objects you'll encounter in Terraform will originate in providers though, so a more general answer that will work for any object you can refer to in an expression is to run terraform console and then ask it for the type of the value in question:
> type(data.local_sensitive_file.public_key)
object({
    content: string,
    content_base64: string,
    filename: string,
    id: string,
})

Unfortunately for a resource (either a resource or data block) it won't yet have a known type until it's been created or read for the first time, and so if your configuration isn't valid then you would need to make it valid enough to run terraform apply successfully before you could use this technique. But for objects that are defined within the Terraform configuration itself, rather than by external operations that haven't run yet, the console is a useful way to inspect data and data types.

> **Comments:**
> **username_0**: your answer is better than mine, thanks for coming in after with it.  

---

### Answer by username_0 on 2023-02-14. Score: 2

You can find the keys with
terraform show -json |
  jq '.values[].resources[] | select(.address=="data.local_sensitive_file.public_key").values | keys'

Which should return,
[
  "content",
  "content_base64",
  "filename",
  "id"
]

Alternatively you can look up local_sensitive_file in the docs.

> **Comments:**
> **username_1**: It doesn't work: first item is null. Try it yourself!  

---

