- Notifications
You must be signed in to change notification settings - Fork24
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
015311951a26859716cd3db2d0cba7da0555e47b1dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
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": { | ||
mtojek marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| 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 resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
| 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{{ | ||