@@ -2,6 +2,8 @@ package types
22
33import (
44 "github.com/google/uuid"
5+ "github.com/zclconf/go-cty/cty"
6+ "github.com/zclconf/go-cty/cty/gocty"
57)
68
79// Based on https://github.com/coder/terraform-provider-coder/blob/9a745586b23a9cb5de2f65a2dcac12e48b134ffa/provider/workspace_owner.go#L72
@@ -25,7 +27,52 @@ type WorkspaceOwner struct {
2527 RBACRoles []WorkspaceOwnerRBACRole `json:"rbac_roles"`
2628}
2729
30+ func (o * WorkspaceOwner ) ToCtyValue () (cty.Value , error ) {
31+ convertedGroups , err := gocty .ToCtyValue (o .Groups , cty .List (cty .String ))
32+ if err != nil {
33+ return cty.Value {}, err
34+ }
35+
36+ roleValues := make ([]cty.Value , 0 , len (o .RBACRoles ))
37+ for _ , role := range o .RBACRoles {
38+ roleValue , err := role .ToCtyValue ()
39+ if err != nil {
40+ return cty.Value {}, err
41+ }
42+ roleValues = append (roleValues , roleValue )
43+ }
44+ var convertedRoles cty.Value = cty .ListValEmpty (WorkspaceOwnerRBACRole {}.CtyType ())
45+ if len (roleValues ) > 0 {
46+ convertedRoles = cty .ListVal (roleValues )
47+ }
48+
49+ return cty .ObjectVal (map [string ]cty.Value {
50+ "id" : cty .StringVal (o .ID .String ()),
51+ "name" : cty .StringVal (o .Name ),
52+ "full_name" : cty .StringVal (o .FullName ),
53+ "email" : cty .StringVal (o .Email ),
54+ "ssh_public_key" : cty .StringVal (o .SSHPublicKey ),
55+ "groups" : convertedGroups ,
56+ "login_type" : cty .StringVal (o .LoginType ),
57+ "rbac_roles" : convertedRoles ,
58+ }), nil
59+ }
60+
2861type WorkspaceOwnerRBACRole struct {
2962 Name string `json:"name"`
3063 OrgID uuid.UUID `json:"org_id"`
3164}
65+
66+ func (_ WorkspaceOwnerRBACRole ) CtyType () cty.Type {
67+ return cty .Object (map [string ]cty.Type {
68+ "name" : cty .String ,
69+ "org_id" : cty .String ,
70+ })
71+ }
72+
73+ func (r * WorkspaceOwnerRBACRole ) ToCtyValue () (cty.Value , error ) {
74+ return cty .ObjectVal (map [string ]cty.Value {
75+ "name" : cty .StringVal (r .Name ),
76+ "org_id" : cty .StringVal (r .OrgID .String ()),
77+ }), nil
78+ }
0 commit comments