Skip to content

Commit 4453f33

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/opts_validate
2 parents ed766d0 + fe28dd6 commit 4453f33

File tree

7 files changed

+86
-98
lines changed

7 files changed

+86
-98
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
<br>
1515
<br>
1616

17-
[Quickstart](#quickstart) | [Docs](https://coder.com/docs) |
17+
[Coder Repo](https://github.com/coder/coder) |
18+
[Docs](https://coder.com/docs) |
1819
[Why Coder](https://coder.com/why) |
1920
[Premium](https://coder.com/pricing#compare-plans)
2021

@@ -27,14 +28,18 @@
2728

2829
</div>
2930

30-
This repository contains a component of Coder that handles workspace parameter
31-
management via Terraform. It's responsible for extracting and managing
31+
This repository contains a component of Coder, currently called Preview, that extracts and manages
3232
[workspace parameters](https://coder.com/docs/admin/templates/extending-templates/parameters)
33-
from Terraform configurations, supporting [Coder's](https://coder.com) core
34-
functionality of creating cloud development environments (like EC2 VMs,
35-
Kubernetes Pods, and Docker containers).
33+
from Terraform configurations.
3634

37-
The primary repository for Coder is [here](https://github.com/coder/coder).
35+
It provides real-time validation to verify user selections and compatibility while presenting dynamic form controls that
36+
adapt based on previous choices.
37+
38+
As users select parameters from the template, Preview validates the selection for compatibility and user entitlements.
39+
The form updates other fields based on the selections and only shows relevant and compatible options.
40+
41+
Once Preview is incorporated in Coder, it will allow template admins to use a variety of form controls with dependencies
42+
from which users can deploy their ideal workspaces.
3843

3944
<!--Should update this with the new cool form options -->
4045
<p align="center">

go.mod

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
module github.com/coder/preview
22

3-
go 1.24
4-
5-
toolchain go1.24.1
3+
go 1.24.2
64

75
require (
86
cdr.dev/slog v1.6.2-0.20240126064726-20367d4aede6
97
github.com/aquasecurity/trivy v0.58.2
108
github.com/coder/guts v1.0.2-0.20250227211802-139809366a22
119
github.com/coder/serpent v0.10.0
12-
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre0.0.20250414140516-f66adaca2adf
10+
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre1.0.20250417100258-c86bb5c3ddcd
1311
github.com/coder/websocket v1.8.13
1412
github.com/go-chi/chi v4.1.2+incompatible
15-
github.com/google/uuid v1.6.0
1613
github.com/hashicorp/go-version v1.7.0
1714
github.com/hashicorp/hc-install v0.9.2
1815
github.com/hashicorp/hcl/v2 v2.23.0
@@ -67,6 +64,7 @@ require (
6764
github.com/google/go-cmp v0.7.0 // indirect
6865
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect
6966
github.com/google/s2a-go v0.1.9 // indirect
67+
github.com/google/uuid v1.6.0 // indirect
7068
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
7169
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
7270
github.com/hashicorp/errwrap v1.1.0 // indirect
@@ -84,7 +82,6 @@ require (
8482
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1 // indirect
8583
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24 // indirect
8684
github.com/klauspost/compress v1.17.11 // indirect
87-
github.com/liamg/memoryfs v1.6.0 // indirect
8885
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
8986
github.com/mattn/go-colorable v0.1.14 // indirect
9087
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -120,15 +117,15 @@ require (
120117
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
121118
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
122119
go.opentelemetry.io/otel/trace v1.34.0 // indirect
123-
golang.org/x/crypto v0.35.0 // indirect
120+
golang.org/x/crypto v0.36.0 // indirect
124121
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
125122
golang.org/x/mod v0.24.0 // indirect
126-
golang.org/x/net v0.36.0 // indirect
123+
golang.org/x/net v0.38.0 // indirect
127124
golang.org/x/oauth2 v0.26.0 // indirect
128-
golang.org/x/sync v0.11.0 // indirect
129-
golang.org/x/sys v0.30.0 // indirect
130-
golang.org/x/term v0.29.0 // indirect
131-
golang.org/x/text v0.22.0 // indirect
125+
golang.org/x/sync v0.12.0 // indirect
126+
golang.org/x/sys v0.31.0 // indirect
127+
golang.org/x/term v0.30.0 // indirect
128+
golang.org/x/text v0.23.0 // indirect
132129
golang.org/x/time v0.10.0 // indirect
133130
golang.org/x/tools v0.30.0 // indirect
134131
google.golang.org/api v0.218.0 // indirect

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx
718718
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
719719
github.com/coder/serpent v0.10.0 h1:ofVk9FJXSek+SmL3yVE3GoArP83M+1tX+H7S4t8BSuM=
720720
github.com/coder/serpent v0.10.0/go.mod h1:cZFW6/fP+kE9nd/oRkEHJpG6sXCtQ+AX7WMMEHv0Y3Q=
721-
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre0.0.20250414140516-f66adaca2adf h1:h0ZMBLv/NiHeMWANSiUKHZkuxti4zIWCGXAXYF0tuJQ=
722-
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre0.0.20250414140516-f66adaca2adf/go.mod h1:X28s3rz+aEM5PkBKvk3xcUrQFO2eNPjzRChUg9wb70U=
721+
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre1.0.20250417100258-c86bb5c3ddcd h1:FsIG6Fd0YOEK7D0Hl/CJywRA+Y6Gd5RQbSIa2L+/BmE=
722+
github.com/coder/terraform-provider-coder/v2 v2.4.0-pre1.0.20250417100258-c86bb5c3ddcd/go.mod h1:56/KdGYaA+VbwXJbTI8CA57XPfnuTxN8rjxbR34PbZw=
723723
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
724724
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
725725
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
@@ -1250,8 +1250,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
12501250
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
12511251
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
12521252
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
1253-
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
1254-
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
1253+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
1254+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
12551255
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
12561256
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
12571257
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -1379,8 +1379,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
13791379
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
13801380
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
13811381
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
1382-
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
1383-
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
1382+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
1383+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
13841384
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
13851385
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
13861386
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1432,8 +1432,8 @@ golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
14321432
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
14331433
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
14341434
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
1435-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
1436-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
1435+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
1436+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
14371437
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
14381438
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
14391439
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1518,8 +1518,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15181518
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15191519
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
15201520
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1521-
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
1522-
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1521+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
1522+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
15231523
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
15241524
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
15251525
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -1535,8 +1535,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
15351535
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
15361536
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
15371537
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
1538-
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
1539-
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
1538+
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
1539+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
15401540
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
15411541
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
15421542
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1557,8 +1557,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
15571557
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
15581558
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
15591559
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
1560-
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
1561-
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
1560+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
1561+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
15621562
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
15631563
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
15641564
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

owner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"github.com/aquasecurity/trivy/pkg/iac/terraform"
77
tfcontext "github.com/aquasecurity/trivy/pkg/iac/terraform/context"
88
"github.com/zclconf/go-cty/cty"
9+
"golang.org/x/xerrors"
910
)
1011

11-
func workspaceOwnerHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value), error) {
12+
func workspaceOwnerHook(_ fs.FS, input Input) (func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value), error) {
1213
ownerValue, err := input.Owner.ToCtyValue()
1314
if err != nil {
14-
return nil, err
15+
return nil, xerrors.Errorf("failed to convert owner value", err)
1516
}
1617

1718
return func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value) {

types/owner.go

Lines changed: 38 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,62 @@
11
package types
22

33
import (
4-
"github.com/google/uuid"
54
"github.com/zclconf/go-cty/cty"
65
"github.com/zclconf/go-cty/cty/gocty"
6+
"golang.org/x/xerrors"
77
)
88

99
// Based on https://github.com/coder/terraform-provider-coder/blob/9a745586b23a9cb5de2f65a2dcac12e48b134ffa/provider/workspace_owner.go#L72
1010
type WorkspaceOwner struct {
11-
ID uuid.UUID `json:"id"`
12-
Name string `json:"name"`
13-
FullName string `json:"full_name"`
14-
Email string `json:"email"`
15-
SSHPublicKey string `json:"ssh_public_key"`
11+
ID string `json:"id" cty:"id"`
12+
Name string `json:"name" cty:"name"`
13+
FullName string `json:"full_name" cty:"full_name"`
14+
Email string `json:"email" cty:"email"`
15+
SSHPublicKey string `json:"ssh_public_key" cty:"ssh_public_key"`
1616
// SSHPrivateKey is intentionally omitted for now, due to the security risk
1717
// that exposing it poses.
18-
// SSHPrivateKey string `json:"ssh_private_key"`
19-
Groups []string `json:"groups"`
18+
// SSHPrivateKey string `json:"ssh_private_key" cty:"ssh_private_key"`
19+
Groups []string `json:"groups" cty:"groups"`
2020
// SessionToken is intentionally omitted for now, due to the security risk
2121
// that exposing it poses.
22-
// SessionToken string `json:"session_token"`
22+
// SessionToken string `json:"session_token" cty:"session_token"`
2323
// OIDCAccessToken is intentionally omitted for now, due to the security risk
2424
// that exposing it poses.
25-
// OIDCAccessToken string `json:"oidc_access_token"`
26-
LoginType string `json:"login_type"`
27-
RBACRoles []WorkspaceOwnerRBACRole `json:"rbac_roles"`
25+
// OIDCAccessToken string `json:"oidc_access_token" cty:"oidc_access_token"`
26+
LoginType string `json:"login_type" cty:"login_type"`
27+
RBACRoles []WorkspaceOwnerRBACRole `json:"rbac_roles" cty:"rbac_roles"`
28+
}
29+
30+
type WorkspaceOwnerRBACRole struct {
31+
Name string `json:"name" cty:"name"`
32+
OrgID string `json:"org_id" cty:"org_id"`
2833
}
2934

3035
func (o *WorkspaceOwner) ToCtyValue() (cty.Value, error) {
3136
if o.Groups == nil {
32-
o.Groups = []string{}
37+
o.Groups = make([]string, 0)
3338
}
34-
convertedGroups, err := gocty.ToCtyValue(o.Groups, cty.List(cty.String))
35-
if err != nil {
36-
return cty.Value{}, err
39+
if o.RBACRoles == nil {
40+
o.RBACRoles = make([]WorkspaceOwnerRBACRole, 0)
3741
}
3842

39-
roleValues := make([]cty.Value, 0, len(o.RBACRoles))
40-
for _, role := range o.RBACRoles {
41-
roleValue, err := role.ToCtyValue()
42-
if err != nil {
43-
return cty.Value{}, err
44-
}
45-
roleValues = append(roleValues, roleValue)
46-
}
47-
var convertedRoles cty.Value = cty.ListValEmpty(WorkspaceOwnerRBACRole{}.CtyType())
48-
if len(roleValues) > 0 {
49-
convertedRoles = cty.ListVal(roleValues)
43+
ownerValue, err := gocty.ToCtyValue(o, cty.Object(map[string]cty.Type{
44+
"id": cty.String,
45+
"name": cty.String,
46+
"full_name": cty.String,
47+
"email": cty.String,
48+
"ssh_public_key": cty.String,
49+
"groups": cty.List(cty.String),
50+
"login_type": cty.String,
51+
"rbac_roles": cty.List(cty.Object(
52+
map[string]cty.Type{
53+
"name": cty.String,
54+
"org_id": cty.String,
55+
},
56+
)),
57+
}))
58+
if err != nil {
59+
return cty.Value{}, xerrors.Errorf("failed to convert owner value", err)
5060
}
51-
52-
return cty.ObjectVal(map[string]cty.Value{
53-
"id": cty.StringVal(o.ID.String()),
54-
"name": cty.StringVal(o.Name),
55-
"full_name": cty.StringVal(o.FullName),
56-
"email": cty.StringVal(o.Email),
57-
"ssh_public_key": cty.StringVal(o.SSHPublicKey),
58-
"groups": convertedGroups,
59-
"login_type": cty.StringVal(o.LoginType),
60-
"rbac_roles": convertedRoles,
61-
}), nil
62-
}
63-
64-
type WorkspaceOwnerRBACRole struct {
65-
Name string `json:"name"`
66-
OrgID uuid.UUID `json:"org_id"`
67-
}
68-
69-
func (_ WorkspaceOwnerRBACRole) CtyType() cty.Type {
70-
return cty.Object(map[string]cty.Type{
71-
"name": cty.String,
72-
"org_id": cty.String,
73-
})
74-
}
75-
76-
func (r *WorkspaceOwnerRBACRole) ToCtyValue() (cty.Value, error) {
77-
return cty.ObjectVal(map[string]cty.Value{
78-
"name": cty.StringVal(r.Name),
79-
"org_id": cty.StringVal(r.OrgID.String()),
80-
}), nil
61+
return ownerValue, nil
8162
}

types/owner_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package types
33
import (
44
"testing"
55

6-
"github.com/google/uuid"
76
"github.com/stretchr/testify/require"
87
)
98

109
func TestToCtyValue(t *testing.T) {
1110
owner := WorkspaceOwner{
12-
ID: uuid.MustParse("f6457744-3e16-45b2-b3b0-80c2df491c99"),
11+
ID: "f6457744-3e16-45b2-b3b0-80c2df491c99",
1312
Name: "Nissa",
1413
FullName: "Nissa, Worldwaker",
1514
@@ -18,14 +17,14 @@ func TestToCtyValue(t *testing.T) {
1817
LoginType: "password",
1918
RBACRoles: []WorkspaceOwnerRBACRole{
2019
{Name: "User Admin"},
21-
{Name: "Organization User Admin", OrgID: uuid.MustParse("5af9253a-ecde-4a71-b8f5-c8d15be9e52b")},
20+
{Name: "Organization User Admin", OrgID: "5af9253a-ecde-4a71-b8f5-c8d15be9e52b"},
2221
},
2322
}
2423

2524
ownerValue, err := owner.ToCtyValue()
2625
require.NoError(t, err)
2726

28-
require.Equal(t, owner.ID.String(), ownerValue.AsValueMap()["id"].AsString())
27+
require.Equal(t, owner.ID, ownerValue.AsValueMap()["id"].AsString())
2928
require.Equal(t, owner.Name, ownerValue.AsValueMap()["name"].AsString())
3029
require.Equal(t, owner.SSHPublicKey, ownerValue.AsValueMap()["ssh_public_key"].AsString())
3130
for i, it := range owner.Groups {
@@ -34,13 +33,13 @@ func TestToCtyValue(t *testing.T) {
3433
for i, it := range owner.RBACRoles {
3534
roleValueMap := ownerValue.AsValueMap()["rbac_roles"].AsValueSlice()[i].AsValueMap()
3635
require.Equal(t, it.Name, roleValueMap["name"].AsString())
37-
require.Equal(t, it.OrgID.String(), roleValueMap["org_id"].AsString())
36+
require.Equal(t, it.OrgID, roleValueMap["org_id"].AsString())
3837
}
3938
}
4039

4140
func TestToCtyValueWithNilLists(t *testing.T) {
4241
owner := WorkspaceOwner{
43-
ID: uuid.MustParse("f6457744-3e16-45b2-b3b0-80c2df491c99"),
42+
ID: "f6457744-3e16-45b2-b3b0-80c2df491c99",
4443
Name: "Nissa",
4544
FullName: "Nissa, Worldwaker",
4645

warnings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package preview
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/aquasecurity/trivy/pkg/iac/terraform"
78
"github.com/hashicorp/hcl/v2"
@@ -24,6 +25,10 @@ func unexpandedCountBlocks(modules terraform.Modules) hcl.Diagnostics {
2425
for _, block := range modules.GetBlocks() {
2526
block := block
2627

28+
// Only warn on coder blocks
29+
if !strings.HasPrefix(block.NameLabel(), "coder_") {
30+
continue
31+
}
2732
if countAttr, ok := block.Attributes()["count"]; ok {
2833
if block.IsExpanded() {
2934
continue

0 commit comments

Comments
 (0)