Thanks to visit codestin.com
Credit goes to github.com

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

+1
Loading

docs/images/icons/table-rows.svg

+1
Loading

docs/images/metadata-ui.png

848 KB
Loading

docs/manifest.json

+8-1
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

+60
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)