Skip to content

Commit 99ba884

Browse files
authored
feat: add optional property to coder_external_auth (#185)
1 parent 1797a03 commit 99ba884

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

docs/data-sources/external_auth.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Use this data source to require users to authenticate with an external service p
1919

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

22+
### Optional
23+
24+
- `optional` (Boolean) Authenticating with the external auth provider is not required, and can be skipped by users when creating or updating workspaces
25+
2226
### Read-Only
2327

2428
- `access_token` (String) The access token returned by the external auth provider. This can be used to pre-authenticate command-line tools.

provider/externalauth.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ func externalAuthDataSource() *schema.Resource {
3232
},
3333
"access_token": {
3434
Type: schema.TypeString,
35-
Computed: true,
3635
Description: "The access token returned by the external auth provider. This can be used to pre-authenticate command-line tools.",
36+
Computed: true,
37+
},
38+
"optional": {
39+
Type: schema.TypeBool,
40+
Description: "Authenticating with the external auth provider is not required, and can be skipped by users when creating or updating workspaces",
41+
Optional: true,
3742
},
3843
},
3944
}

provider/externalauth_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,40 @@ func TestExternalAuth(t *testing.T) {
3636

3737
attribs := resource.Primary.Attributes
3838
require.Equal(t, "github", attribs["id"])
39+
require.Equal(t, "", attribs["optional"])
40+
41+
return nil
42+
},
43+
}},
44+
})
45+
}
46+
47+
func TestOptionalExternalAuth(t *testing.T) {
48+
t.Parallel()
49+
50+
resource.Test(t, resource.TestCase{
51+
Providers: map[string]*schema.Provider{
52+
"coder": provider.New(),
53+
},
54+
IsUnitTest: true,
55+
Steps: []resource.TestStep{{
56+
Config: `
57+
provider "coder" {
58+
}
59+
data "coder_external_auth" "github" {
60+
id = "github"
61+
optional = true
62+
}
63+
`,
64+
Check: func(state *terraform.State) error {
65+
require.Len(t, state.Modules, 1)
66+
require.Len(t, state.Modules[0].Resources, 1)
67+
resource := state.Modules[0].Resources["data.coder_external_auth.github"]
68+
require.NotNil(t, resource)
69+
70+
attribs := resource.Primary.Attributes
71+
require.Equal(t, "github", attribs["id"])
72+
require.Equal(t, "true", attribs["optional"])
3973

4074
return nil
4175
},

0 commit comments

Comments
 (0)