From 533ea48e0461e43933aae2a880563653e6e247ad Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 22 Feb 2023 19:49:21 +0000 Subject: [PATCH] feat: add `coder_git_auth` data source This data source enables template authors to require git authentication for specific providers on workspace build. --- docs/data-sources/git_auth.md | 50 +++++++++++++++++++ .../coder_git_auth/data-source.tf | 21 ++++++++ provider/gitauth.go | 49 ++++++++++++++++++ provider/gitauth_test.go | 44 ++++++++++++++++ provider/provider.go | 1 + 5 files changed, 165 insertions(+) create mode 100644 docs/data-sources/git_auth.md create mode 100644 examples/data-sources/coder_git_auth/data-source.tf create mode 100644 provider/gitauth.go create mode 100644 provider/gitauth_test.go diff --git a/docs/data-sources/git_auth.md b/docs/data-sources/git_auth.md new file mode 100644 index 00000000..5573993d --- /dev/null +++ b/docs/data-sources/git_auth.md @@ -0,0 +1,50 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "coder_git_auth Data Source - terraform-provider-coder" +subcategory: "" +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. +--- + +# coder_git_auth (Data Source) + +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. + +## Example Usage + +```terraform +provider "coder" { +} + +data "coder_git_auth" "github" { + # Matches the ID of the git auth provider in Coder. + id = "github" +} + +resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + dir = "~/coder" + env = { + GITHUB_TOKEN : data.coder_git_auth.github.access_token + } + startup_script = < +## Schema + +### Required + +- `id` (String) The identifier of a configured git auth provider set up in your Coder deployment. + +### Read-Only + +- `access_token` (String) The access token returned by the git authentication provider. This can be used to pre-authenticate command-line tools. + + diff --git a/examples/data-sources/coder_git_auth/data-source.tf b/examples/data-sources/coder_git_auth/data-source.tf new file mode 100644 index 00000000..eeed89aa --- /dev/null +++ b/examples/data-sources/coder_git_auth/data-source.tf @@ -0,0 +1,21 @@ +provider "coder" { +} + +data "coder_git_auth" "github" { + # Matches the ID of the git auth provider in Coder. + id = "github" +} + +resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + dir = "~/coder" + env = { + GITHUB_TOKEN : data.coder_git_auth.github.access_token + } + startup_script = <