Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add order to coder_metadata#450

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
BrunoQuaresma wants to merge6 commits intomain
base:main
Choose a base branch
Loading
frombq/feat-order-metadta
Open
Show file tree
Hide file tree
Changes fromall 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
4 changes: 4 additions & 0 deletionsdocs/resources/metadata.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,16 +43,19 @@ resource "coder_metadata" "pod_info" {
item {
key = "description"
value = "This description will show up in the Coder dashboard."
order = 1
}
item {
key = "pod_uid"
value = kubernetes_pod.dev[0].uid
order = 2
}
item {
key = "public_key"
value = tls_private_key.example_key_pair.public_key_openssh
# The value of this item will be hidden from view by default
sensitive = true
order = 3
}
}
```
Expand DownExpand Up@@ -84,6 +87,7 @@ Required:

Optional:

- `order` (Number) The order determines the position of item in the UI presentation. The lowest order is shown first and items with equal order are sorted by key (ascending order).
- `sensitive` (Boolean) Set to `true` to for items such as API keys whose values should be hidden from view by default. Note that this does not prevent metadata from being retrieved using the API, so it is not suitable for secrets that should not be exposed to workspace users.
- `value` (String) The value of this metadata item. Supports basic Markdown, including hyperlinks.

Expand Down
3 changes: 3 additions & 0 deletionsexamples/resources/coder_metadata/resource.tf
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,15 +25,18 @@ resource "coder_metadata" "pod_info" {
item {
key = "description"
value = "This description will show up in the Coder dashboard."
order = 1
}
item {
key = "pod_uid"
value = kubernetes_pod.dev[0].uid
order = 2
}
item {
key = "public_key"
value = tls_private_key.example_key_pair.public_key_openssh
# The value of this item will be hidden from view by default
sensitive = true
order = 3
}
}
6 changes: 6 additions & 0 deletionsprovider/metadata.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,6 +103,12 @@ func metadataResource() *schema.Resource {
ForceNew: true,
Computed: true,
},
"order": {
Type: schema.TypeInt,
Description: "The order determines the position of item in the UI presentation. The lowest order is shown first and items with equal order are sorted by key (ascending order).",
ForceNew: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hm... isForceNew necessary@johnstcn ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not 100% sure, but it is already used inagent.metadata.order so it may be no harm to be safe and stick to the status quo.

mtojek reacted with thumbs up emoji
Optional: true,
},
},
},
},
Expand Down
9 changes: 9 additions & 0 deletionsprovider/metadata_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,17 +35,21 @@ func TestMetadata(t *testing.T) {
key = "secret"
value = "squirrel"
sensitive = true
order = 1
}
item {
key = "implicit_null"
order = 2
}
item {
key = "explicit_null"
value = null
order = 3
}
item {
key = "empty"
value = ""
order = 4
}
}
`,
Expand All@@ -66,19 +70,24 @@ func TestMetadata(t *testing.T) {
"item.0.key": "foo",
"item.0.value": "bar",
"item.0.sensitive": "false",
"item.0.order": "0",
"item.1.key": "secret",
"item.1.value": "squirrel",
"item.1.sensitive": "true",
"item.1.order": "1",
"item.2.key": "implicit_null",
"item.2.is_null": "true",
"item.2.sensitive": "false",
"item.2.order": "2",
"item.3.key": "explicit_null",
"item.3.is_null": "true",
"item.3.sensitive": "false",
"item.3.order": "3",
"item.4.key": "empty",
"item.4.value": "",
"item.4.is_null": "false",
"item.4.sensitive": "false",
"item.4.order": "4",
} {
require.Equal(t, expected, metadata.Primary.Attributes[key])
}
Expand Down
16 changes: 16 additions & 0 deletionsprovider/provider.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@ import (
"strings"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/go-cty/cty/gocty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"golang.org/x/xerrors"
Expand DownExpand Up@@ -99,10 +100,16 @@ func populateIsNull(resourceData *schema.ResourceData) (result interface{}, err
var resultItems []interface{}
for _, item := range items {
key := valueAsString(item.GetAttr("key"))
order, err := valueAsInt(item.GetAttr("order"))
if err != nil {
return nil, xerrors.Errorf("unable to parse order for coder_metadata item %q: %w", key, err)
}

resultItem := map[string]interface{}{
"key": key,
"value": valueAsString(item.GetAttr("value")),
"sensitive": valueAsBool(item.GetAttr("sensitive")),
"order": order,
}
if item.GetAttr("value").IsNull() {
resultItem["is_null"] = true
Expand DownExpand Up@@ -132,6 +139,15 @@ func valueAsBool(value cty.Value) interface{} {
return value.True()
}

func valueAsInt(value cty.Value) (interface{}, error) {
if value.IsNull() {
return nil, nil
}
var valueAsInt int64
err := gocty.FromCtyValue(value, &valueAsInt)
return valueAsInt, err
}
Comment on lines +142 to +149
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

With this change, it would be good to have a test for a non-numeric value fororder.


// errorAsDiagnostic transforms a Go error to a diag.Diagnostics object representing a fatal error.
func errorAsDiagnostics(err error) diag.Diagnostics {
return []diag.Diagnostic{{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp