Skip to content
Closed
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
14 changes: 8 additions & 6 deletions owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ func workspaceOwnerHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, bl
if input.Owner.Groups == nil {
input.Owner.Groups = []string{}
}
ownerGroups, err := gocty.ToCtyValue(input.Owner.Groups, cty.List(cty.String))

ownerType, err := gocty.ImpliedType(input.Owner)
if err != nil {
return nil, xerrors.Errorf("converting owner groups: %w", err)
return nil, xerrors.Errorf("getting owner cty type: %w", err)
}

ownerValue := cty.ObjectVal(map[string]cty.Value{
"groups": ownerGroups,
})
ownerValues, err := gocty.ToCtyValue(input.Owner, ownerType)
if err != nil {
return nil, xerrors.Errorf("converting owner context to cty: %w", err)
}

return func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value) {
for _, block := range blocks.OfType("data") {
// TODO: Does it have to be me?
if block.TypeLabel() == "coder_workspace_owner" && block.NameLabel() == "me" {
block.Context().Parent().Set(ownerValue,
block.Context().Parent().Set(ownerValues,
"data", block.TypeLabel(), block.NameLabel())
}
}
Expand Down
Loading