-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathexternalauth.go
52 lines (45 loc) · 1.82 KB
/
externalauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/coder/terraform-provider-coder/provider/helpers"
)
// externalAuthDataSource returns a schema for an external authentication data source.
func externalAuthDataSource() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Description: "Use this data source to require users to authenticate with an external service prior to workspace creation. This can be used to [pre-authenticate external services](https://coder.com/docs/admin/external-auth) in a workspace. (e.g. Google Cloud, Github, Docker, etc.)",
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
id, ok := rd.Get("id").(string)
if !ok || id == "" {
return diag.Errorf("id is required")
}
rd.SetId(id)
accessToken := helpers.OptionalEnv(ExternalAuthAccessTokenEnvironmentVariable(id))
rd.Set("access_token", accessToken)
return nil
},
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "The ID of a configured external auth provider set up in your Coder deployment.",
Required: true,
},
"access_token": {
Type: schema.TypeString,
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,
},
},
}
}
func ExternalAuthAccessTokenEnvironmentVariable(id string) string {
return fmt.Sprintf("CODER_EXTERNAL_AUTH_ACCESS_TOKEN_%s", id)
}