Skip to content

feat: add coder_secret data source for user secrets#501

Merged
zedkipp merged 1 commit intomainfrom
zedkipp/plat-108-coder-secret-data-source
Apr 22, 2026
Merged

feat: add coder_secret data source for user secrets#501
zedkipp merged 1 commit intomainfrom
zedkipp/plat-108-coder-secret-data-source

Conversation

@zedkipp
Copy link
Copy Markdown
Contributor

@zedkipp zedkipp commented Apr 10, 2026

Add a new coder_secret data source that allows template authors to declare required user secrets and access their values during workspace builds.

Schema:

  • env (optional) — environment variable name the secret injects
  • file (optional) — file path the secret injects
  • help_message (required) — guidance shown when the secret is missing
  • value (computed, sensitive) — resolved from provisioner env vars

Exactly one of env or file must be set. On start transitions, a missing secret fails the build with the help_message. On stop/delete, missing secrets return empty to allow teardown.

Env var convention:

  • Env secrets: CODER_SECRET_ENV_{env_name}
  • File secrets: CODER_SECRET_FILE_{hex(file_path)}

RFC: https://www.notion.so/coderhq/User-Secrets-32cd579be59280a98192dec7b3b5daf1

Related coder PR: coder/coder#24542

@zedkipp zedkipp force-pushed the zedkipp/plat-108-coder-secret-data-source branch 4 times, most recently from cf0b74b to ca847f0 Compare April 20, 2026 18:10
Comment thread provider/provider.go Outdated
Comment thread examples/data-sources/coder_secret/data-source.tf
Comment thread provider/secret.go Outdated
return diag.Diagnostics{{
Severity: diag.Error,
Summary: fmt.Sprintf("Missing required secret: %s", requirement),
Detail: detail.String(),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the diagnostic looks like all together:

Image

@zedkipp zedkipp marked this pull request as ready for review April 21, 2026 22:06
Comment thread provider/secret.go
Copy link
Copy Markdown
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just one note regarding the control flow in the data source.

Comment thread provider/secret.go Outdated
Comment thread provider/secret.go Outdated
@zedkipp zedkipp force-pushed the zedkipp/plat-108-coder-secret-data-source branch from 100f37e to 70ee398 Compare April 22, 2026 14:42
Comment thread provider/secret.go Outdated
Comment thread provider/secret.go
Add a new `coder_secret` data source that allows template authors to
declare required user secrets and access their values during workspace
builds.

Schema:
- `env` (optional) — environment variable name the secret injects
- `file` (optional) — file path the secret injects
- `help_message` (required) — guidance shown when the secret is missing
- `value` (computed, sensitive) — resolved from provisioner env vars

Exactly one of `env` or `file` must be set. On start transitions, a
missing secret fails the build with the help_message. On stop/delete,
missing secrets return empty to allow teardown.

Env var convention:
- Env secrets: CODER_SECRET_ENV_{env_name}
- File secrets: CODER_SECRET_FILE_{hex(file_path)}
@zedkipp zedkipp force-pushed the zedkipp/plat-108-coder-secret-data-source branch from 70ee398 to 93f2334 Compare April 22, 2026 16:06
@zedkipp zedkipp merged commit af77cd5 into main Apr 22, 2026
7 checks passed
@zedkipp zedkipp deleted the zedkipp/plat-108-coder-secret-data-source branch April 22, 2026 18:40
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants