-
Notifications
You must be signed in to change notification settings - Fork 23
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0153119
51a2685
9716cd3
db2d0cb
a7da055
5e47b1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure, but it is already used in |
||
| Optional: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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 | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 for |
||
|
|
||
| // errorAsDiagnostic transforms a Go error to a diag.Diagnostics object representing a fatal error. | ||
| func errorAsDiagnostics(err error) diag.Diagnostics { | ||
| return []diag.Diagnostic{{ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.