Skip to content

Commit 3ceee76

Browse files
authored
docs: explain resource metadata (#3447)
1 parent c73f708 commit 3ceee76

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

docs/images/icons/key.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/images/icons/table-rows.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/images/metadata-ui.png

848 KB
Loading

docs/manifest.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@
6161
{
6262
"title": "Provider Authentication",
6363
"description": "Learn how to authenticate the provisioner",
64-
"path": "./templates/authentication.md"
64+
"path": "./templates/authentication.md",
65+
"icon_path": "./images/icons/key.svg"
66+
},
67+
{
68+
"title": "Resource Metadata",
69+
"description": "Learn how to expose resource data to users",
70+
"path": "./templates/resource-metadata.md",
71+
"icon_path": "./images/icons/table-rows.svg"
6572
}
6673
]
6774
},

docs/templates/resource-metadata.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Resource Metadata
2+
3+
Expose key workspace information to your users via [`coder_metadata`](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/metadata) resources in your template code.
4+
5+
![ui](../images/metadata-ui.png)
6+
7+
<blockquote class="info">
8+
Coder automatically generates the <code>type</code> metadata.
9+
</blockquote>
10+
11+
You can use `coder_metadata` to show
12+
13+
- Compute resources
14+
- IP addresses
15+
- [Secrets](../secrets.md#displaying-secrets)
16+
- Important file paths
17+
18+
and any other Terraform resource attribute.
19+
20+
## Example
21+
22+
Expose the disk size, deployment name, and persistent
23+
directory in a Kubernetes template with:
24+
25+
```hcl
26+
resource "kubernetes_persistent_volume_claim" "root" {
27+
...
28+
}
29+
30+
resource "kubernetes_deployment" "coder" {
31+
# My deployment is ephemeral
32+
count = data.coder_workspace.me.start_count
33+
...
34+
}
35+
36+
resource "coder_metadata" "pvc" {
37+
resource_id = kubernetes_persistent_volume_claim.root.id
38+
item {
39+
key = "size"
40+
value = kubernetes_persistent_volume_claim.root.spec[0].resources[0].requests.storage
41+
}
42+
item {
43+
key = "dir"
44+
value = "/home/coder"
45+
}
46+
}
47+
48+
resource "coder_metadata" "deployment" {
49+
count = data.coder_workspace.me.start_count
50+
resource_id = kubernetes_deployment.coder[0].id
51+
item {
52+
key = "name"
53+
value = kubernetes_deployment.coder[0].metadata[0].name
54+
}
55+
}
56+
```
57+
58+
## Up next
59+
60+
- Learn about [secrets](../secrets.md)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy