Skip to content

feat: add optional property to coder_external_auth #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions docs/data-sources/external_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Use this data source to require users to authenticate with an external service p

- `id` (String) The ID of a configured external auth provider set up in your Coder deployment.

### Optional

- `optional` (Boolean) Authenticating with the external auth provider is not required, and can be skipped by users when creating or updating workspaces

### Read-Only

- `access_token` (String) The access token returned by the external auth provider. This can be used to pre-authenticate command-line tools.
7 changes: 6 additions & 1 deletion provider/externalauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ func externalAuthDataSource() *schema.Resource {
},
"access_token": {
Type: schema.TypeString,
Computed: true,
Description: "The access token returned by the external auth provider. This can be used to pre-authenticate command-line tools.",
Computed: true,
},
"optional": {
Type: schema.TypeBool,
Description: "Authenticating with the external auth provider is not required, and can be skipped by users when creating or updating workspaces",
Optional: true,
},
},
}
Expand Down
34 changes: 34 additions & 0 deletions provider/externalauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ func TestExternalAuth(t *testing.T) {

attribs := resource.Primary.Attributes
require.Equal(t, "github", attribs["id"])
require.Equal(t, "", attribs["optional"])

return nil
},
}},
})
}

func TestOptionalExternalAuth(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
"coder": provider.New(),
},
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
}
data "coder_external_auth" "github" {
id = "github"
optional = true
}
`,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
require.Len(t, state.Modules[0].Resources, 1)
resource := state.Modules[0].Resources["data.coder_external_auth.github"]
require.NotNil(t, resource)

attribs := resource.Primary.Attributes
require.Equal(t, "github", attribs["id"])
require.Equal(t, "true", attribs["optional"])

return nil
},
Expand Down