From b4ff7ce5eabedf20ee4741057d465274f7a0dad3 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Thu, 27 Jun 2024 22:14:59 +0000 Subject: [PATCH 1/9] coder_env code example --- examples/resources/coder_env/resource.tf | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/resources/coder_env/resource.tf diff --git a/examples/resources/coder_env/resource.tf b/examples/resources/coder_env/resource.tf new file mode 100644 index 00000000..9f8e28f2 --- /dev/null +++ b/examples/resources/coder_env/resource.tf @@ -0,0 +1,19 @@ +data "coder_workspace" "me" {} + +resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + dir = "/workspace" +} + +resource "coder_env" "welcome_message" { + agent_id = coder_agent.dev.id + name = "WELCOME_MESSAGE" + value = "Welcome to your Coder workspace!" +} + +resource "coder_env" "internal_api_url" { + agent_id = coder_agent.dev.id + name = "INTERNAL_API_URL" + value = "https://api.internal.company.com/v1" +} \ No newline at end of file From 821bfecf86bcbbdd538034812e2679fb93244297 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 20:39:15 +0000 Subject: [PATCH 2/9] added coder_script example --- examples/resources/coder_script/resource.tf | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/resources/coder_script/resource.tf diff --git a/examples/resources/coder_script/resource.tf b/examples/resources/coder_script/resource.tf new file mode 100644 index 00000000..e3315ff8 --- /dev/null +++ b/examples/resources/coder_script/resource.tf @@ -0,0 +1,52 @@ +data "coder_workspace" "me" {} + +resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + dir = "/workspace" +} + +resource "coder_script" "dotfiles" { + agent_id = coder_agent.dev.agent_id + display_name = "Dotfiles" + icon = "/icon/dotfiles.svg" + run_on_start = true + script = templatefile("~/get_dotfiles.sh", { + DOTFILES_URI : var.dotfiles_uri, + DOTFILES_USER : var.dotfiles_user + }) +} + +resource "coder_script" "code-server" { + agent_id = coder_agent.dev.agent_id + display_name = "code-server" + icon = "/icon/code.svg" + run_on_start = true + start_blocks_login = true + script = templatefile("./install-code-server.sh", { + LOG_PATH : "/tmp/code-server.log" + }) +} + +resource "coder_script" "nightly_sleep_reminder" { + agent_id = coder_agent.dev.agent_id + display_name = "Nightly update" + icon = "/icon/database.svg" + cron = "0 22 * * *" + script = </tmp/pid.log 2>&1 & + EOF +} \ No newline at end of file From db3bfe017ff4c4afc7fa467faa98d2f7e5577bfd Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 20:41:54 +0000 Subject: [PATCH 3/9] updated coder_script description to note parallelism --- examples/resources/coder_script/resource.tf | 12 ++++++------ provider/script.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/resources/coder_script/resource.tf b/examples/resources/coder_script/resource.tf index e3315ff8..b7fced38 100644 --- a/examples/resources/coder_script/resource.tf +++ b/examples/resources/coder_script/resource.tf @@ -33,7 +33,7 @@ resource "coder_script" "nightly_sleep_reminder" { display_name = "Nightly update" icon = "/icon/database.svg" cron = "0 22 * * *" - script = </tmp/pid.log 2>&1 & EOF diff --git a/provider/script.go b/provider/script.go index 1474dbd2..536a5732 100644 --- a/provider/script.go +++ b/provider/script.go @@ -17,7 +17,7 @@ func scriptResource() *schema.Resource { return &schema.Resource{ SchemaVersion: 1, - Description: "Use this resource to run a script from an agent.", + Description: "Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel.", CreateContext: func(_ context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics { rd.SetId(uuid.NewString()) runOnStart, _ := rd.Get("run_on_start").(bool) From a6be2426a92c6f047d5a167741321ab913e48799 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 20:52:58 +0000 Subject: [PATCH 4/9] short coder_external_auth example --- .../data-sources/coder_external_auth/data-source.tf | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 examples/data-sources/coder_external_auth/data-source.tf diff --git a/examples/data-sources/coder_external_auth/data-source.tf b/examples/data-sources/coder_external_auth/data-source.tf new file mode 100644 index 00000000..330ff216 --- /dev/null +++ b/examples/data-sources/coder_external_auth/data-source.tf @@ -0,0 +1,11 @@ +provider "coder" {} + + +data "coder_external_auth" "github" { + id = "github" +} + +data "coder_external_auth" "azure-identity" { + id = "azure-identiy" + optional = true +} From 031b5d08bf22c3fd004158cc66ded0bd005d2c04 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 20:54:38 +0000 Subject: [PATCH 5/9] added external auth link, make gen --- docs/data-sources/external_auth.md | 18 ++++++++- docs/resources/env.md | 24 +++++++++++- docs/resources/script.md | 59 +++++++++++++++++++++++++++++- provider/externalauth.go | 2 +- 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/docs/data-sources/external_auth.md b/docs/data-sources/external_auth.md index af4df43b..e4089f24 100644 --- a/docs/data-sources/external_auth.md +++ b/docs/data-sources/external_auth.md @@ -3,14 +3,28 @@ 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) + 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.) --- # 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) +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.) +## Example Usage +```terraform +provider "coder" {} + + +data "coder_external_auth" "github" { + id = "github" +} + +data "coder_external_auth" "azure-identity" { + id = "azure-identiy" + optional = true +} +``` ## Schema diff --git a/docs/resources/env.md b/docs/resources/env.md index b948bad9..3531335c 100644 --- a/docs/resources/env.md +++ b/docs/resources/env.md @@ -10,7 +10,29 @@ description: |- Use this resource to set an environment variable in a workspace. Note that this resource cannot be used to overwrite existing environment variables set on the "coder_agent" resource. - +## Example Usage + +```terraform +data "coder_workspace" "me" {} + +resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + dir = "/workspace" +} + +resource "coder_env" "welcome_message" { + agent_id = coder_agent.dev.id + name = "WELCOME_MESSAGE" + value = "Welcome to your Coder workspace!" +} + +resource "coder_env" "internal_api_url" { + agent_id = coder_agent.dev.id + name = "INTERNAL_API_URL" + value = "https://api.internal.company.com/v1" +} +``` ## Schema diff --git a/docs/resources/script.md b/docs/resources/script.md index a16b39f5..d4d5dd9f 100644 --- a/docs/resources/script.md +++ b/docs/resources/script.md @@ -3,14 +3,69 @@ page_title: "coder_script Resource - terraform-provider-coder" subcategory: "" description: |- - Use this resource to run a script from an agent. + Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel. --- # coder_script (Resource) -Use this resource to run a script from an agent. +Use this resource to run a script from an agent. When multiple scripts are assigned to the same agent, they are executed in parallel. +## Example Usage +```terraform +data "coder_workspace" "me" {} + +resource "coder_agent" "dev" { + os = "linux" + arch = "amd64" + dir = "/workspace" +} + +resource "coder_script" "dotfiles" { + agent_id = coder_agent.dev.agent_id + display_name = "Dotfiles" + icon = "/icon/dotfiles.svg" + run_on_start = true + script = templatefile("~/get_dotfiles.sh", { + DOTFILES_URI : var.dotfiles_uri, + DOTFILES_USER : var.dotfiles_user + }) +} + +resource "coder_script" "code-server" { + agent_id = coder_agent.dev.agent_id + display_name = "code-server" + icon = "/icon/code.svg" + run_on_start = true + start_blocks_login = true + script = templatefile("./install-code-server.sh", { + LOG_PATH : "/tmp/code-server.log" + }) +} + +resource "coder_script" "nightly_sleep_reminder" { + agent_id = coder_agent.dev.agent_id + display_name = "Nightly update" + icon = "/icon/database.svg" + cron = "0 22 * * *" + script = </tmp/pid.log 2>&1 & + EOF +} +``` ## Schema diff --git a/provider/externalauth.go b/provider/externalauth.go index 13c85fab..a11a67c4 100644 --- a/provider/externalauth.go +++ b/provider/externalauth.go @@ -15,7 +15,7 @@ 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 in a workspace. (e.g. gcloud, gh, docker, etc)", + 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 == "" { From a3befe96cbfcbd352a2b6c0a99c7f05c094fdb7f Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 21:30:01 +0000 Subject: [PATCH 6/9] fixed icon link for coder_parameter --- docs/data-sources/parameter.md | 2 +- provider/parameter.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/parameter.md b/docs/data-sources/parameter.md index 9c6a11f5..178c6d9d 100644 --- a/docs/data-sources/parameter.md +++ b/docs/data-sources/parameter.md @@ -145,7 +145,7 @@ data "coder_parameter" "home_volume_size" { - `description` (String) Describe what this parameter does. - `display_name` (String) The displayed name of the parameter as it will appear in the interface. - `ephemeral` (Boolean) The value of an ephemeral parameter will not be preserved between consecutive workspace builds. -- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `data.coder_workspace.me.access_url + "/icon/"`. +- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons [here](https://github.com/coder/coder/tree/main/site/static/icon). Use a built-in icon with `data.coder_workspace.me.access_url + "/icon/"`. - `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution! - `option` (Block List, Max: 64) Each "option" block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option)) - `order` (Number) The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order). diff --git a/provider/parameter.go b/provider/parameter.go index d0f71dab..281537f6 100644 --- a/provider/parameter.go +++ b/provider/parameter.go @@ -220,7 +220,7 @@ func parameterDataSource() *schema.Resource { "icon": { Type: schema.TypeString, Description: "A URL to an icon that will display in the dashboard. View built-in " + - "icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a " + + "icons [here](https://github.com/coder/coder/tree/main/site/static/icon). Use a " + "built-in icon with `data.coder_workspace.me.access_url + \"/icon/\"`.", ForceNew: true, Optional: true, From 4901de59388d49518f952449a521b7f471a16b2d Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 21:33:53 +0000 Subject: [PATCH 7/9] coder_provisioner example --- docs/data-sources/provisioner.md | 20 +++++++++++++++++++ .../coder_provisioner/data-source.tf | 17 ++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 examples/data-sources/coder_provisioner/data-source.tf diff --git a/docs/data-sources/provisioner.md b/docs/data-sources/provisioner.md index 4316aeea..157505bd 100644 --- a/docs/data-sources/provisioner.md +++ b/docs/data-sources/provisioner.md @@ -10,7 +10,27 @@ description: |- Use this data source to get information about the Coder provisioner. +## Example Usage +```terraform +provider "coder" {} + +data "coder_provisioner" "dev" {} + +data "coder_workspace" "dev" {} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.dev.arch + os = data.coder_provisioner.dev.os + dir = "/workspace" + display_apps { + vscode = true + vscode_insiders = false + web_terminal = true + ssh_helper = false + } +} +``` ## Schema diff --git a/examples/data-sources/coder_provisioner/data-source.tf b/examples/data-sources/coder_provisioner/data-source.tf new file mode 100644 index 00000000..a94823ed --- /dev/null +++ b/examples/data-sources/coder_provisioner/data-source.tf @@ -0,0 +1,17 @@ +provider "coder" {} + +data "coder_provisioner" "dev" {} + +data "coder_workspace" "dev" {} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.dev.arch + os = data.coder_provisioner.dev.os + dir = "/workspace" + display_apps { + vscode = true + vscode_insiders = false + web_terminal = true + ssh_helper = false + } +} \ No newline at end of file From bc12d487b8553290fe5177dc17ff5c4521268c22 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 28 Jun 2024 21:35:56 +0000 Subject: [PATCH 8/9] fixed inline links for provisioner --- docs/data-sources/provisioner.md | 4 ++-- provider/provisioner.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/data-sources/provisioner.md b/docs/data-sources/provisioner.md index 157505bd..ba930a2a 100644 --- a/docs/data-sources/provisioner.md +++ b/docs/data-sources/provisioner.md @@ -37,6 +37,6 @@ resource "coder_agent" "main" { ### Read-Only -- `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants). +- `arch` (String) The architecture of the host. This exposes `runtime.GOARCH` (see [Go constants](https://pkg.go.dev/runtime#pkg-constants)). - `id` (String) The ID of this resource. -- `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants). +- `os` (String) The operating system of the host. This exposes `runtime.GOOS` (see [Go constants](https://pkg.go.dev/runtime#pkg-constants)). diff --git a/provider/provisioner.go b/provider/provisioner.go index 9d356798..49a40d21 100644 --- a/provider/provisioner.go +++ b/provider/provisioner.go @@ -29,12 +29,12 @@ func provisionerDataSource() *schema.Resource { "os": { Type: schema.TypeString, Computed: true, - Description: "The operating system of the host. This exposes `runtime.GOOS` (see https://pkg.go.dev/runtime#pkg-constants).", + Description: "The operating system of the host. This exposes `runtime.GOOS` (see [Go constants](https://pkg.go.dev/runtime#pkg-constants)).", }, "arch": { Type: schema.TypeString, Computed: true, - Description: "The architecture of the host. This exposes `runtime.GOARCH` (see https://pkg.go.dev/runtime#pkg-constants).", + Description: "The architecture of the host. This exposes `runtime.GOARCH` (see [Go constants](https://pkg.go.dev/runtime#pkg-constants)).", }, }, } From 4de7aeb42a4e616ac403ec1168fbcc0a4293c1d6 Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Sun, 30 Jun 2024 19:10:04 +0000 Subject: [PATCH 9/9] added coder_workspace_owner examples --- docs/data-sources/workspace_owner.md | 31 +++++++++++++++++++ .../coder_workspace_owner/data-source.tf | 28 +++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 examples/data-sources/coder_workspace_owner/data-source.tf diff --git a/docs/data-sources/workspace_owner.md b/docs/data-sources/workspace_owner.md index 646b1340..0deff622 100644 --- a/docs/data-sources/workspace_owner.md +++ b/docs/data-sources/workspace_owner.md @@ -10,7 +10,38 @@ description: |- Use this data source to fetch information about the workspace owner. +## Example Usage +```terraform +provider "coder" {} + +data "coder_workspace" "me" {} + +data "coder_workspace_owner" "me" {} + +resource "coder_agent" "dev" { + arch = "amd64" + os = "linux" + dir = local.repo_dir + env = { + OIDC_TOKEN : data.coder_workspace_owner.me.oidc_access_token, + } +} + +# Add git credentials from coder_workspace_owner +resource "coder_env" "git_author_name" { + agent_id = coder_agent.agent_id + name = "GIT_AUTHOR_NAME" + value = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) +} + +resource "coder_env" "git_author_email" { + agent_id = var.agent_id + name = "GIT_AUTHOR_EMAIL" + value = data.coder_workspace_owner.me.email + count = data.coder_workspace_owner.me.email != "" ? 1 : 0 +} +``` ## Schema diff --git a/examples/data-sources/coder_workspace_owner/data-source.tf b/examples/data-sources/coder_workspace_owner/data-source.tf new file mode 100644 index 00000000..fc27db6c --- /dev/null +++ b/examples/data-sources/coder_workspace_owner/data-source.tf @@ -0,0 +1,28 @@ +provider "coder" {} + +data "coder_workspace" "me" {} + +data "coder_workspace_owner" "me" {} + +resource "coder_agent" "dev" { + arch = "amd64" + os = "linux" + dir = local.repo_dir + env = { + OIDC_TOKEN : data.coder_workspace_owner.me.oidc_access_token, + } +} + +# Add git credentials from coder_workspace_owner +resource "coder_env" "git_author_name" { + agent_id = coder_agent.agent_id + name = "GIT_AUTHOR_NAME" + value = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) +} + +resource "coder_env" "git_author_email" { + agent_id = var.agent_id + name = "GIT_AUTHOR_EMAIL" + value = data.coder_workspace_owner.me.email + count = data.coder_workspace_owner.me.email != "" ? 1 : 0 +} \ No newline at end of file