Skip to content

Commit

Permalink
docs: explain resource metadata (#3447)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammario committed Aug 10, 2022
1 parent c73f708 commit 3ceee76
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/images/icons/key.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/icons/table-rows.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/metadata-ui.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@
{
"title": "Provider Authentication",
"description": "Learn how to authenticate the provisioner",
"path": "./templates/authentication.md"
"path": "./templates/authentication.md",
"icon_path": "./images/icons/key.svg"
},
{
"title": "Resource Metadata",
"description": "Learn how to expose resource data to users",
"path": "./templates/resource-metadata.md",
"icon_path": "./images/icons/table-rows.svg"
}
]
},
Expand Down
60 changes: 60 additions & 0 deletions docs/templates/resource-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Resource Metadata

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.

![ui](../images/metadata-ui.png)

<blockquote class="info">
Coder automatically generates the <code>type</code> metadata.
</blockquote>

You can use `coder_metadata` to show

- Compute resources
- IP addresses
- [Secrets](../secrets.md#displaying-secrets)
- Important file paths

and any other Terraform resource attribute.

## Example

Expose the disk size, deployment name, and persistent
directory in a Kubernetes template with:

```hcl
resource "kubernetes_persistent_volume_claim" "root" {
...
}
resource "kubernetes_deployment" "coder" {
# My deployment is ephemeral
count = data.coder_workspace.me.start_count
...
}
resource "coder_metadata" "pvc" {
resource_id = kubernetes_persistent_volume_claim.root.id
item {
key = "size"
value = kubernetes_persistent_volume_claim.root.spec[0].resources[0].requests.storage
}
item {
key = "dir"
value = "/home/coder"
}
}
resource "coder_metadata" "deployment" {
count = data.coder_workspace.me.start_count
resource_id = kubernetes_deployment.coder[0].id
item {
key = "name"
value = kubernetes_deployment.coder[0].metadata[0].name
}
}
```

## Up next

- Learn about [secrets](../secrets.md)

0 comments on commit 3ceee76

Please sign in to comment.