Skip to content

Add cost field to resource_metadata #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/resources/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ resource "tls_private_key" "example_key_pair" {
resource "coder_metadata" "pod_info" {
count = data.coder_workspace.me.start_count
resource_id = kubernetes_pod.dev[0].id
# (Enterprise-only) this resource consumes 200 quota units
cost = 200
item {
key = "description"
value = "This description will show up in the Coder dashboard."
Expand Down Expand Up @@ -55,6 +57,7 @@ resource "coder_metadata" "pod_info" {

### Optional

- `cost` (Number) (Enterprise) The amount of quota units this resource consumes
- `hide` (Boolean) Hide the resource from the UI.
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icons/<path>"`.

Expand Down
2 changes: 2 additions & 0 deletions examples/resources/coder_metadata/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ resource "tls_private_key" "example_key_pair" {
resource "coder_metadata" "pod_info" {
count = data.coder_workspace.me.start_count
resource_id = kubernetes_pod.dev[0].id
# (Enterprise-only) this resource consumes 200 quota units
cost = 200
item {
key = "description"
value = "This description will show up in the Coder dashboard."
Expand Down
6 changes: 6 additions & 0 deletions provider/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func metadataResource() *schema.Resource {
return nil, nil
},
},
"cost": {
Type: schema.TypeInt,
Description: "(Enterprise) The amount of quota units this resource consumes",
ForceNew: true,
Optional: true,
},
"item": {
Type: schema.TypeList,
Description: "Each \"item\" block defines a single metadata item consisting of a key/value pair.",
Expand Down
2 changes: 2 additions & 0 deletions provider/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestMetadata(t *testing.T) {
resource_id = coder_agent.dev.id
hide = true
icon = "/icons/storage.svg"
cost = 200
item {
key = "foo"
value = "bar"
Expand Down Expand Up @@ -65,6 +66,7 @@ func TestMetadata(t *testing.T) {
"resource_id": agent.Primary.Attributes["id"],
"hide": "true",
"icon": "/icons/storage.svg",
"cost": "200",
"item.#": "5",
"item.0.key": "foo",
"item.0.value": "bar",
Expand Down