-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add coder_external_auth
and deprecate coder_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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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 provider prior to workspace creation. This can be used to pre-authenticate external services in a workspace. | ||
--- | ||
|
||
# coder_external_auth (Data Source) | ||
|
||
Use this data source to require users to authenticate with an external provider prior to workspace creation. This can be used to pre-authenticate external services in a workspace. | ||
|
||
|
||
|
||
<!-- 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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 provider prior to workspace creation. This can be used to pre-authenticate external services in a workspace.", | ||
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) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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 | ||
}, | ||
}}, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't want to mix up things with terraform providers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an example with the gcloud CLI? I think the terms "provider" "service" and "application" would all be confusing as to what it actually does but one single example could go a long way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure