Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 144ff73

Browse files
authoredJul 15, 2024··
chore: add acceptance tests to user resource (#22)
1 parent d841872 commit 144ff73

File tree

7 files changed

+278
-214
lines changed

7 files changed

+278
-214
lines changed
 

‎.github/workflows/test.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ name: Tests
66
on:
77
pull_request:
88
paths-ignore:
9-
- 'README.md'
9+
- "README.md"
1010
push:
11+
branches:
12+
- main
1113
paths-ignore:
12-
- 'README.md'
14+
- "README.md"
1315

1416
# Testing only needs permissions to read the repository contents.
1517
permissions:
@@ -25,7 +27,7 @@ jobs:
2527
- uses: actions/checkout@v4
2628
- uses: actions/setup-go@v5
2729
with:
28-
go-version-file: 'go.mod'
30+
go-version-file: "go.mod"
2931
cache: true
3032
- run: go mod download
3133
- run: go build -v .
@@ -40,7 +42,7 @@ jobs:
4042
- uses: actions/checkout@v4
4143
- uses: actions/setup-go@v5
4244
with:
43-
go-version-file: 'go.mod'
45+
go-version-file: "go.mod"
4446
cache: true
4547
- run: go generate ./...
4648
- name: git diff
@@ -59,20 +61,21 @@ jobs:
5961
matrix:
6062
# list whatever Terraform versions here you would like to support
6163
terraform:
62-
- '1.0.*'
63-
- '1.1.*'
64-
- '1.2.*'
65-
- '1.3.*'
66-
- '1.4.*'
64+
- "1.0.*"
65+
- "1.1.*"
66+
- "1.2.*"
67+
- "1.3.*"
68+
- "1.4.*"
6769
- "1.5.*"
6870
- "1.6.*"
6971
- "1.7.*"
7072
- "1.8.*"
73+
- "1.9.*"
7174
steps:
7275
- uses: actions/checkout@v4
7376
- uses: actions/setup-go@v5
7477
with:
75-
go-version-file: 'go.mod'
78+
go-version-file: "go.mod"
7679
cache: true
7780
- uses: hashicorp/setup-terraform@v3
7881
with:
@@ -84,7 +87,6 @@ jobs:
8487
run: go test -v -cover ./internal/provider/
8588
timeout-minutes: 10
8689

87-
8890
lint:
8991
name: Lint
9092
runs-on: ubuntu-latest
@@ -98,7 +100,7 @@ jobs:
98100

99101
- uses: hashicorp/setup-terraform@v3
100102
with:
101-
terraform_version: "1.8.*"
103+
terraform_version: "1.9.*"
102104
terraform_wrapper: false
103105

104106
- name: Check out code into the Go module directory

‎go.mod

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/coder/terraform-provider-coderd
22

3-
go 1.22.3
3+
go 1.22.4
4+
5+
toolchain go1.22.5
46

57
require (
68
cdr.dev/slog v1.6.2-0.20240126064726-20367d4aede6
@@ -45,7 +47,7 @@ require (
4547
github.com/cloudflare/circl v1.3.7 // indirect
4648
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 // indirect
4749
github.com/coder/serpent v0.7.0 // indirect
48-
github.com/coder/terraform-provider-coder v0.22.0 // indirect
50+
github.com/coder/terraform-provider-coder v0.23.0 // indirect
4951
github.com/containerd/log v0.1.0 // indirect
5052
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
5153
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -75,7 +77,7 @@ require (
7577
github.com/hashicorp/go-uuid v1.0.3 // indirect
7678
github.com/hashicorp/go-version v1.7.0 // indirect
7779
github.com/hashicorp/hc-install v0.7.0 // indirect
78-
github.com/hashicorp/hcl/v2 v2.20.1 // indirect
80+
github.com/hashicorp/hcl/v2 v2.21.0 // indirect
7981
github.com/hashicorp/logutils v1.0.0 // indirect
8082
github.com/hashicorp/terraform-exec v0.21.0 // indirect
8183
github.com/hashicorp/terraform-json v0.22.1 // indirect
@@ -85,7 +87,7 @@ require (
8587
github.com/hashicorp/yamux v0.1.1 // indirect
8688
github.com/huandu/xstrings v1.3.3 // indirect
8789
github.com/imdario/mergo v0.3.15 // indirect
88-
github.com/klauspost/compress v1.17.7 // indirect
90+
github.com/klauspost/compress v1.17.9 // indirect
8991
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
9092
github.com/mattn/go-colorable v0.1.13 // indirect
9193
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -121,7 +123,7 @@ require (
121123
github.com/spf13/cast v1.6.0 // indirect
122124
github.com/spf13/pflag v1.0.5 // indirect
123125
github.com/tinylib/msgp v1.1.8 // indirect
124-
github.com/valyala/fasthttp v1.54.0 // indirect
126+
github.com/valyala/fasthttp v1.55.0 // indirect
125127
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
126128
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
127129
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
@@ -141,21 +143,21 @@ require (
141143
go.opentelemetry.io/otel/trace v1.27.0 // indirect
142144
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
143145
go.uber.org/atomic v1.11.0 // indirect
144-
golang.org/x/crypto v0.23.0 // indirect
146+
golang.org/x/crypto v0.24.0 // indirect
145147
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
146-
golang.org/x/mod v0.17.0 // indirect
147-
golang.org/x/net v0.25.0 // indirect
148+
golang.org/x/mod v0.18.0 // indirect
149+
golang.org/x/net v0.26.0 // indirect
148150
golang.org/x/oauth2 v0.20.0 // indirect
149151
golang.org/x/sync v0.7.0 // indirect
150-
golang.org/x/sys v0.20.0 // indirect
151-
golang.org/x/term v0.20.0 // indirect
152-
golang.org/x/text v0.15.0 // indirect
152+
golang.org/x/sys v0.21.0 // indirect
153+
golang.org/x/term v0.21.0 // indirect
154+
golang.org/x/text v0.16.0 // indirect
153155
golang.org/x/time v0.5.0 // indirect
154-
golang.org/x/tools v0.21.0 // indirect
156+
golang.org/x/tools v0.22.0 // indirect
155157
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
156158
google.golang.org/appengine v1.6.8 // indirect
157159
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
158-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
160+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect
159161
google.golang.org/grpc v1.64.0 // indirect
160162
google.golang.org/protobuf v1.34.1 // indirect
161163
gopkg.in/DataDog/dd-trace-go.v1 v1.64.0 // indirect

‎go.sum

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx
8787
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
8888
github.com/coder/serpent v0.7.0 h1:zGpD2GlF3lKIVkMjNGKbkip88qzd5r/TRcc30X/SrT0=
8989
github.com/coder/serpent v0.7.0/go.mod h1:REkJ5ZFHQUWFTPLExhXYZ1CaHFjxvGNRlLXLdsI08YA=
90-
github.com/coder/terraform-provider-coder v0.22.0 h1:L72WFa9/6sc/nnXENPS8LpWi/2NBV+DRUW0WT//pEaU=
91-
github.com/coder/terraform-provider-coder v0.22.0/go.mod h1:wMun9UZ9HT2CzF6qPPBup1odzBpVUc0/xSFoXgdI3tk=
90+
github.com/coder/terraform-provider-coder v0.23.0 h1:DuNLWxhnGlXyG0g+OCAZRI6xd8+bJjIEnE4F3hYgA4E=
91+
github.com/coder/terraform-provider-coder v0.23.0/go.mod h1:wMun9UZ9HT2CzF6qPPBup1odzBpVUc0/xSFoXgdI3tk=
9292
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
9393
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
9494
github.com/coreos/go-oidc/v3 v3.10.0 h1:tDnXHnLyiTVyT/2zLDGj09pFPkhND8Gl8lnTRhoEaJU=
@@ -225,8 +225,8 @@ github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKe
225225
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
226226
github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk=
227227
github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA=
228-
github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc=
229-
github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4=
228+
github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14=
229+
github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
230230
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
231231
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
232232
github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ=
@@ -274,8 +274,8 @@ github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF
274274
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
275275
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
276276
github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
277-
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
278-
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
277+
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
278+
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
279279
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
280280
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
281281
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -423,8 +423,8 @@ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4d
423423
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
424424
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
425425
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
426-
github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0=
427-
github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM=
426+
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
427+
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
428428
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
429429
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
430430
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
@@ -448,8 +448,8 @@ github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUei
448448
github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0=
449449
github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8=
450450
github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
451-
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
452-
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
451+
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
452+
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
453453
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
454454
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
455455
github.com/zeebo/errs v1.3.0 h1:hmiaKqgYZzcVgRL1Vkc1Mn2914BbzB0IBxs+ebeutGs=
@@ -494,17 +494,17 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
494494
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
495495
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
496496
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
497-
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
498-
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
497+
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
498+
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
499499
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
500500
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
501501
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
502502
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
503503
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
504504
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
505505
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
506-
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
507-
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
506+
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
507+
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
508508
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
509509
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
510510
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -515,8 +515,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
515515
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
516516
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
517517
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
518-
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
519-
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
518+
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
519+
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
520520
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
521521
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
522522
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -550,24 +550,24 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
550550
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
551551
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
552552
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
553-
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
554-
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
553+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
554+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
555555
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
556556
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
557557
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
558558
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
559559
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
560-
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
561-
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
560+
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
561+
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
562562
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
563563
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
564564
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
565565
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
566566
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
567567
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
568568
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
569-
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
570-
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
569+
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
570+
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
571571
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
572572
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
573573
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
@@ -578,8 +578,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
578578
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
579579
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
580580
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
581-
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
582-
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
581+
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
582+
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
583583
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
584584
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
585585
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -593,8 +593,8 @@ google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda h1:wu/KJm9KJwpfHWh
593593
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda/go.mod h1:g2LLCvCeCSir/JJSWosk19BR4NVxGqHUC6rxIRsd7Aw=
594594
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ=
595595
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
596-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI=
597-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
596+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e h1:Elxv5MwEkCI9f5SkoL6afed6NTdxaGoAo39eANBwHL8=
597+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
598598
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
599599
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
600600
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=

‎integration/integration.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io"
7+
"net"
8+
"net/url"
9+
"os"
10+
"testing"
11+
"time"
12+
13+
"github.com/coder/coder/v2/codersdk"
14+
"github.com/docker/docker/api/types/container"
15+
"github.com/docker/docker/api/types/image"
16+
"github.com/docker/docker/client"
17+
"github.com/docker/go-connections/nat"
18+
19+
"github.com/stretchr/testify/require"
20+
)
21+
22+
func StartCoder(ctx context.Context, t *testing.T, name string) *codersdk.Client {
23+
coderImg := os.Getenv("CODER_IMAGE")
24+
if coderImg == "" {
25+
coderImg = "ghcr.io/coder/coder"
26+
}
27+
28+
coderVersion := os.Getenv("CODER_VERSION")
29+
if coderVersion == "" {
30+
coderVersion = "latest"
31+
}
32+
33+
t.Logf("using coder image %s:%s", coderImg, coderVersion)
34+
35+
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
36+
require.NoError(t, err, "init docker client")
37+
38+
p := randomPort(t)
39+
t.Logf("random port is %d", p)
40+
// Stand up a temporary Coder instance
41+
puller, err := cli.ImagePull(ctx, coderImg+":"+coderVersion, image.PullOptions{})
42+
require.NoError(t, err, "pull coder image")
43+
defer puller.Close()
44+
_, err = io.Copy(os.Stderr, puller)
45+
require.NoError(t, err, "pull coder image")
46+
ctr, err := cli.ContainerCreate(ctx, &container.Config{
47+
Image: coderImg + ":" + coderVersion,
48+
Env: []string{
49+
"CODER_HTTP_ADDRESS=0.0.0.0:3000", // Listen on all interfaces inside the container
50+
"CODER_ACCESS_URL=http://localhost:3000", // Set explicitly to avoid creating try.coder.app URLs.
51+
"CODER_IN_MEMORY=true", // We don't necessarily care about real persistence here.
52+
"CODER_TELEMETRY_ENABLE=false", // Avoid creating noise.
53+
},
54+
Labels: map[string]string{},
55+
ExposedPorts: map[nat.Port]struct{}{nat.Port("3000/tcp"): {}},
56+
}, &container.HostConfig{
57+
PortBindings: map[nat.Port][]nat.PortBinding{
58+
nat.Port("3000/tcp"): {{HostIP: "127.0.0.1", HostPort: fmt.Sprintf("%d", p)}},
59+
},
60+
}, nil, nil, "terraform-provider-coderd-"+name)
61+
require.NoError(t, err, "create test deployment")
62+
63+
t.Logf("created container %s\n", ctr.ID)
64+
t.Cleanup(func() { // Make sure we clean up after ourselves.
65+
// TODO: also have this execute if you Ctrl+C!
66+
t.Logf("stopping container %s\n", ctr.ID)
67+
_ = cli.ContainerRemove(ctx, ctr.ID, container.RemoveOptions{
68+
Force: true,
69+
})
70+
})
71+
72+
err = cli.ContainerStart(ctx, ctr.ID, container.StartOptions{})
73+
require.NoError(t, err, "start container")
74+
t.Logf("started container %s\n", ctr.ID)
75+
76+
// nolint:gosec // For testing only.
77+
var (
78+
testEmail = "testing@coder.com"
79+
testPassword = "InsecurePassw0rd!"
80+
testUsername = "testing"
81+
)
82+
83+
// Perform first time setup
84+
coderURL, err := url.Parse(fmt.Sprintf("http://localhost:%d", p))
85+
require.NoError(t, err, "parse coder URL")
86+
client := codersdk.New(coderURL)
87+
// Wait for container to come up
88+
require.Eventually(t, func() bool {
89+
_, err := client.BuildInfo(ctx)
90+
if err != nil {
91+
t.Logf("not ready yet: %s", err.Error())
92+
}
93+
return err == nil
94+
}, 10*time.Second, time.Second, "coder failed to become ready in time")
95+
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
96+
Email: testEmail,
97+
Username: testUsername,
98+
Password: testPassword,
99+
})
100+
require.NoError(t, err, "create first user")
101+
resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
102+
Email: testEmail,
103+
Password: testPassword,
104+
})
105+
require.NoError(t, err, "login to coder instance with password")
106+
client.SetSessionToken(resp.SessionToken)
107+
return client
108+
}
109+
110+
// randomPort is a helper function to find a free random port.
111+
// Note that the OS may reallocate the port very quickly, so
112+
// this is not _guaranteed_.
113+
func randomPort(t *testing.T) int {
114+
random, err := net.Listen("tcp", "127.0.0.1:0")
115+
require.NoError(t, err, "failed to listen on localhost")
116+
_ = random.Close()
117+
tcpAddr, valid := random.Addr().(*net.TCPAddr)
118+
require.True(t, valid, "random port address is not a *net.TCPAddr?!")
119+
return tcpAddr.Port
120+
}

‎integration/integration_test.go

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io"
8-
"net"
9-
"net/url"
107
"os"
118
"os/exec"
129
"path/filepath"
@@ -15,10 +12,6 @@ import (
1512
"time"
1613

1714
"github.com/coder/coder/v2/codersdk"
18-
"github.com/docker/docker/api/types/container"
19-
"github.com/docker/docker/api/types/image"
20-
"github.com/docker/docker/client"
21-
"github.com/docker/go-connections/nat"
2215
"github.com/stretchr/testify/assert"
2316
"github.com/stretchr/testify/require"
2417
)
@@ -83,7 +76,7 @@ func TestIntegration(t *testing.T) {
8376
},
8477
} {
8578
t.Run(tt.name, func(t *testing.T) {
86-
client := startCoder(ctx, t, tt.name)
79+
client := StartCoder(ctx, t, tt.name)
8780
wd, err := os.Getwd()
8881
require.NoError(t, err)
8982
srcDir := filepath.Join(wd, tt.name)
@@ -136,103 +129,3 @@ dev_overrides {
136129
})
137130
return tfrcPath
138131
}
139-
140-
func startCoder(ctx context.Context, t *testing.T, name string) *codersdk.Client {
141-
coderImg := os.Getenv("CODER_IMAGE")
142-
if coderImg == "" {
143-
coderImg = "ghcr.io/coder/coder"
144-
}
145-
146-
coderVersion := os.Getenv("CODER_VERSION")
147-
if coderVersion == "" {
148-
coderVersion = "latest"
149-
}
150-
151-
t.Logf("using coder image %s:%s", coderImg, coderVersion)
152-
153-
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
154-
require.NoError(t, err, "init docker client")
155-
156-
p := randomPort(t)
157-
t.Logf("random port is %d", p)
158-
// Stand up a temporary Coder instance
159-
puller, err := cli.ImagePull(ctx, coderImg+":"+coderVersion, image.PullOptions{})
160-
require.NoError(t, err, "pull coder image")
161-
defer puller.Close()
162-
_, err = io.Copy(os.Stderr, puller)
163-
require.NoError(t, err, "pull coder image")
164-
ctr, err := cli.ContainerCreate(ctx, &container.Config{
165-
Image: coderImg + ":" + coderVersion,
166-
Env: []string{
167-
"CODER_HTTP_ADDRESS=0.0.0.0:3000", // Listen on all interfaces inside the container
168-
"CODER_ACCESS_URL=http://localhost:3000", // Set explicitly to avoid creating try.coder.app URLs.
169-
"CODER_IN_MEMORY=true", // We don't necessarily care about real persistence here.
170-
"CODER_TELEMETRY_ENABLE=false", // Avoid creating noise.
171-
},
172-
Labels: map[string]string{},
173-
ExposedPorts: map[nat.Port]struct{}{nat.Port("3000/tcp"): {}},
174-
}, &container.HostConfig{
175-
PortBindings: map[nat.Port][]nat.PortBinding{
176-
nat.Port("3000/tcp"): {{HostIP: "127.0.0.1", HostPort: fmt.Sprintf("%d", p)}},
177-
},
178-
}, nil, nil, "terraform-provider-coderd-"+name)
179-
require.NoError(t, err, "create test deployment")
180-
181-
t.Logf("created container %s\n", ctr.ID)
182-
t.Cleanup(func() { // Make sure we clean up after ourselves.
183-
// TODO: also have this execute if you Ctrl+C!
184-
t.Logf("stopping container %s\n", ctr.ID)
185-
_ = cli.ContainerRemove(ctx, ctr.ID, container.RemoveOptions{
186-
Force: true,
187-
})
188-
})
189-
190-
err = cli.ContainerStart(ctx, ctr.ID, container.StartOptions{})
191-
require.NoError(t, err, "start container")
192-
t.Logf("started container %s\n", ctr.ID)
193-
194-
// nolint:gosec // For testing only.
195-
var (
196-
testEmail = "testing@coder.com"
197-
testPassword = "InsecurePassw0rd!"
198-
testUsername = "testing"
199-
)
200-
201-
// Perform first time setup
202-
coderURL, err := url.Parse(fmt.Sprintf("http://localhost:%d", p))
203-
require.NoError(t, err, "parse coder URL")
204-
client := codersdk.New(coderURL)
205-
// Wait for container to come up
206-
require.Eventually(t, func() bool {
207-
_, err := client.BuildInfo(ctx)
208-
if err != nil {
209-
t.Logf("not ready yet: %s", err.Error())
210-
}
211-
return err == nil
212-
}, 10*time.Second, time.Second, "coder failed to become ready in time")
213-
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
214-
Email: testEmail,
215-
Username: testUsername,
216-
Password: testPassword,
217-
})
218-
require.NoError(t, err, "create first user")
219-
resp, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
220-
Email: testEmail,
221-
Password: testPassword,
222-
})
223-
require.NoError(t, err, "login to coder instance with password")
224-
client.SetSessionToken(resp.SessionToken)
225-
return client
226-
}
227-
228-
// randomPort is a helper function to find a free random port.
229-
// Note that the OS may reallocate the port very quickly, so
230-
// this is not _guaranteed_.
231-
func randomPort(t *testing.T) int {
232-
random, err := net.Listen("tcp", "127.0.0.1:0")
233-
require.NoError(t, err, "failed to listen on localhost")
234-
_ = random.Close()
235-
tcpAddr, valid := random.Addr().(*net.TCPAddr)
236-
require.True(t, valid, "random port address is not a *net.TCPAddr?!")
237-
return tcpAddr.Port
238-
}

‎internal/provider/user_resource_test.go

Lines changed: 97 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,44 @@
33

44
package provider
55

6-
/*
76
import (
7+
"context"
88
"fmt"
99
"strings"
1010
"testing"
11+
"text/template"
1112

13+
"github.com/coder/terraform-provider-coderd/integration"
1214
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
15+
"github.com/stretchr/testify/require"
1316
)
1417

1518
func TestAccUserResource(t *testing.T) {
19+
ctx := context.Background()
20+
client := integration.StartCoder(ctx, t, "user_acc")
21+
22+
cfg1 := testAccUserResourceConfig{
23+
URL: client.URL.String(),
24+
Token: client.SessionToken(),
25+
Username: PtrTo("example"),
26+
Name: PtrTo("Example User"),
27+
Email: PtrTo("example@coder.com"),
28+
Roles: PtrTo([]string{"owner", "auditor"}),
29+
LoginType: PtrTo("password"),
30+
Password: PtrTo("SomeSecurePassword!"),
31+
}
32+
33+
cfg2 := cfg1
34+
cfg2.Username = PtrTo("exampleNew")
35+
cfg2.Name = PtrTo("Example User New")
36+
1637
resource.Test(t, resource.TestCase{
1738
PreCheck: func() { testAccPreCheck(t) },
1839
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
1940
Steps: []resource.TestStep{
2041
// Create and Read testing
2142
{
22-
Config: testAccUserResourceConfig{
23-
Username: "example",
24-
Name: "Example User",
25-
Email: "example@coder.com",
26-
Roles: []string{"owner", "auditor"},
27-
LoginType: "password",
28-
Password: "SomeSecurePassword!",
29-
}.String(),
43+
Config: cfg1.String(t),
3044
Check: resource.ComposeAggregateTestCheckFunc(
3145
resource.TestCheckResourceAttr("coderd_user.test", "username", "example"),
3246
resource.TestCheckResourceAttr("coderd_user.test", "name", "Example User"),
@@ -44,22 +58,12 @@ func TestAccUserResource(t *testing.T) {
4458
ResourceName: "coderd_user.test",
4559
ImportState: true,
4660
ImportStateVerify: true,
47-
// This is not normally necessary, but is here because this
48-
// example code does not have an actual upstream service.
49-
// Once the Read method is able to refresh information from
50-
// the upstream service, this can be removed.
51-
ImportStateVerifyIgnore: []string{"configurable_attribute", "defaulted", "password"},
61+
// We can't pull the password from the API.
62+
ImportStateVerifyIgnore: []string{"password"},
5263
},
5364
// Update and Read testing
5465
{
55-
Config: testAccUserResourceConfig{
56-
Username: "exampleNew",
57-
Name: "Example User New",
58-
Email: "example@coder.com",
59-
Roles: []string{"owner", "auditor"},
60-
LoginType: "password",
61-
Password: "SomeSecurePassword!",
62-
}.String(),
66+
Config: cfg2.String(t),
6367
Check: resource.ComposeAggregateTestCheckFunc(
6468
resource.TestCheckResourceAttr("coderd_user.test", "username", "exampleNew"),
6569
resource.TestCheckResourceAttr("coderd_user.test", "name", "Example User New"),
@@ -71,40 +75,78 @@ func TestAccUserResource(t *testing.T) {
7175
}
7276

7377
type testAccUserResourceConfig struct {
74-
Username string
75-
Name string
76-
Email string
77-
Roles []string
78-
LoginType string
79-
Password string
80-
Suspended bool
78+
URL string
79+
Token string
80+
81+
Username *string
82+
Name *string
83+
Email *string
84+
Roles *[]string
85+
LoginType *string
86+
Password *string
87+
Suspended *bool
8188
}
8289

83-
func (c testAccUserResourceConfig) String() string {
84-
sb := strings.Builder{}
85-
sb.WriteString(`resource "coderd_user" "test" {` + "\n")
86-
sb.WriteString(fmt.Sprintf(" username = %q\n", c.Username))
87-
if c.Name != "" {
88-
sb.WriteString(fmt.Sprintf(" name = %q\n", c.Name))
89-
}
90-
sb.WriteString(fmt.Sprintf(" email = %q\n", c.Email))
91-
if len(c.Roles) > 0 {
92-
rolesQuoted := make([]string, len(c.Roles))
93-
for i, role := range c.Roles {
94-
rolesQuoted[i] = fmt.Sprintf("%q", role)
95-
}
96-
sb.WriteString(fmt.Sprintf(" roles = [%s]\n", strings.Join(rolesQuoted, ", ")))
97-
}
98-
if c.LoginType != "" {
99-
sb.WriteString(fmt.Sprintf(" login_type = %q\n", c.LoginType))
100-
}
101-
if c.Password != "" {
102-
sb.WriteString(fmt.Sprintf(" password = %q\n", c.Password))
103-
}
104-
if c.Suspended {
105-
sb.WriteString(" suspended = true\n")
90+
func (c testAccUserResourceConfig) String(t *testing.T) string {
91+
tpl := `
92+
provider coderd {
93+
url = "{{.URL}}"
94+
token = "{{.Token}}"
95+
}
96+
97+
resource "coderd_user" "test" {
98+
username = {{orNull .Username}}
99+
name = {{orNull .Name}}
100+
email = {{orNull .Email}}
101+
roles = {{orNull .Roles}}
102+
login_type = {{orNull .LoginType}}
103+
password = {{orNull .Password}}
104+
suspended = {{orNull .Suspended}}
105+
}
106+
`
107+
// Define template functions
108+
funcMap := template.FuncMap{
109+
"orNull": func(v interface{}) string {
110+
if v == nil {
111+
return "null"
112+
}
113+
switch value := v.(type) {
114+
case *string:
115+
if value == nil {
116+
return "null"
117+
}
118+
return fmt.Sprintf("%q", *value)
119+
case *bool:
120+
if value == nil {
121+
return "null"
122+
}
123+
return fmt.Sprintf(`%t`, *value)
124+
case *[]string:
125+
if value == nil {
126+
return "null"
127+
}
128+
var result string
129+
for i, role := range *value {
130+
if i > 0 {
131+
result += ", "
132+
}
133+
result += fmt.Sprintf("%q", role)
134+
}
135+
return fmt.Sprintf("[%s]", result)
136+
137+
default:
138+
require.NoError(t, fmt.Errorf("unknown type in template: %T", value))
139+
return ""
140+
}
141+
},
106142
}
107-
sb.WriteString(`}`)
108-
return sb.String()
143+
144+
buf := strings.Builder{}
145+
tmpl, err := template.New("test").Funcs(funcMap).Parse(tpl)
146+
require.NoError(t, err)
147+
148+
err = tmpl.Execute(&buf, c)
149+
require.NoError(t, err)
150+
151+
return buf.String()
109152
}
110-
*/

‎internal/provider/util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package provider
2+
3+
func PtrTo[T any](v T) *T {
4+
return &v
5+
}

0 commit comments

Comments
 (0)
Please sign in to comment.