Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: addcoder_external_auth and deprecatecoder_git_auth#163

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kylecarbs merged 2 commits intomainfromextauth
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
24 changes: 24 additions & 0 deletionsdocs/data-sources/external_auth.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coder_external_auth Data Source - terraform-provider-coder"
subcategory: ""
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 in a workspace. (e.g. gcloud, gh, docker, etc)
---

# coder_external_auth (Data Source)

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 in a workspace. (e.g. gcloud, gh, docker, etc)



<!-- schema generated by tfplugindocs -->
## Schema

### Required

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

### Read-Only

- `access_token` (String) The access token returned by the external auth provider. This can be used to pre-authenticate command-line tools.
44 changes: 44 additions & 0 deletionsprovider/externalauth.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
package provider

import (
"context"
"fmt"
"os"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// externalAuthDataSource returns a schema for an external authentication data source.
func externalAuthDataSource() *schema.Resource {
return &schema.Resource{
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 in a workspace. (e.g. gcloud, gh, 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 := os.Getenv(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,
Computed: true,
Description: "The access token returned by the external auth provider. This can be used to pre-authenticate command-line tools.",
},
},
}
}

func ExternalAuthAccessTokenEnvironmentVariable(id string) string {
return fmt.Sprintf("CODER_EXTERNAL_AUTH_ACCESS_TOKEN_%s", id)
}
44 changes: 44 additions & 0 deletionsprovider/externalauth_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
package provider_test

import (
"testing"

"github.com/coder/terraform-provider-coder/provider"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/stretchr/testify/require"
)

func TestExternalAuth(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"
}
`,
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"])

return nil
},
}},
})
}
3 changes: 2 additions & 1 deletionprovider/gitauth.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,8 @@ import (
// gitAuthDataSource returns a schema for a Git authentication data source.
func gitAuthDataSource() *schema.Resource {
return &schema.Resource{
Description: "Use this data source to require users to authenticate with a Git provider prior to workspace creation. This can be used to perform an authenticated `git clone` in startup scripts.",
DeprecationMessage: "Use the `coder_external_auth` data source instead.",
Description: "Use this data source to require users to authenticate with a Git provider prior to workspace creation. This can be used to perform an authenticated `git clone` in startup scripts.",
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
rawID, ok := rd.GetOk("id")
if !ok {
Expand Down
9 changes: 5 additions & 4 deletionsprovider/provider.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,10 +68,11 @@ func New() *schema.Provider {
}, nil
},
DataSourcesMap: map[string]*schema.Resource{
"coder_workspace": workspaceDataSource(),
"coder_provisioner": provisionerDataSource(),
"coder_parameter": parameterDataSource(),
"coder_git_auth": gitAuthDataSource(),
"coder_workspace": workspaceDataSource(),
"coder_provisioner": provisionerDataSource(),
"coder_parameter": parameterDataSource(),
"coder_git_auth": gitAuthDataSource(),
"coder_external_auth": externalAuthDataSource(),
},
ResourcesMap: map[string]*schema.Resource{
"coder_agent": agentResource(),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp