diff --git a/docs/data-sources/user.md b/docs/data-sources/user.md index ece2778..74f6e80 100644 --- a/docs/data-sources/user.md +++ b/docs/data-sources/user.md @@ -17,8 +17,8 @@ An existing user on the coder deployment ### Optional -- `id` (String) The ID of the user to retrieve. This field will be populated if a username is supplied -- `username` (String) The username of the user to retrieve. This field will be populated if an ID is supplied +- `id` (String) The ID of the user to retrieve. This field will be populated if a username is supplied. +- `username` (String) The username of the user to retrieve. This field will be populated if an ID is supplied. ### Read-Only diff --git a/internal/provider/provider.go b/internal/provider/provider.go index dfc531c..40bdff3 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1,6 +1,3 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - package provider import ( diff --git a/internal/provider/user_data_source_test.go b/internal/provider/user_data_source_test.go index 93573f8..1af225b 100644 --- a/internal/provider/user_data_source_test.go +++ b/internal/provider/user_data_source_test.go @@ -1,10 +1,8 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - package provider /* import ( + "html/template" "strings" "testing" @@ -20,7 +18,7 @@ func TestAccUserDataSource(t *testing.T) { { Config: testAccUserDataSourceConfig{ Username: "example", - }.String(), + }.String(t), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("coderd_user.test", "username", "example"), resource.TestCheckResourceAttr("coderd_user.test", "name", "Example User"), @@ -43,7 +41,7 @@ func TestAccUserDataSource(t *testing.T) { { Config: testAccUserDataSourceConfig{ ID: "example", - }.String(), + }.String(t), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("coderd_user.test", "username", "example"), resource.TestCheckResourceAttr("coderd_user.test", "name", "Example User"), @@ -65,16 +63,25 @@ type testAccUserDataSourceConfig struct { Username string } -func (c testAccUserDataSourceConfig) String() string { - sb := strings.Builder{} - sb.WriteString(`data "coderd_user" "test" {` + "\n") - if c.ID != "" { - sb.WriteString(` id = "` + c.ID + `"` + "\n") - } - if c.Username != "" { - sb.WriteString(` username = "` + c.Username + `"` + "\n") +func (c testAccUserDataSourceConfig) String(t *testing.T) string { + tpl := ` +data "coderd_user" "test" { +{{- if .ID }} + id = "{{ .ID }}" +{{- end }} +{{- if .Username }} + username = "{{ .Username }}" +{{- end }} +}` + + tmpl := template.Must(template.New("userDataSource").Parse(tpl)) + + buf := strings.Builder{} + err := tmpl.Execute(&buf, c) + if err != nil { + panic(err) } - sb.WriteString(`}`) - return sb.String() + + return buf.String() } */ diff --git a/internal/provider/user_resource.go b/internal/provider/user_resource.go index 75bddf6..70a417a 100644 --- a/internal/provider/user_resource.go +++ b/internal/provider/user_resource.go @@ -1,6 +1,3 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - package provider import ( diff --git a/internal/provider/user_resource_test.go b/internal/provider/user_resource_test.go index eaf720c..afa91d7 100644 --- a/internal/provider/user_resource_test.go +++ b/internal/provider/user_resource_test.go @@ -1,6 +1,3 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - package provider /*