Skip to content

feat: extract coder_secret requirements into Output#198

Open
dylanhuff-at-coder wants to merge 1 commit intomainfrom
dylan/plat-100-secret-requirements
Open

feat: extract coder_secret requirements into Output#198
dylanhuff-at-coder wants to merge 1 commit intomainfrom
dylan/plat-100-secret-requirements

Conversation

@dylanhuff-at-coder
Copy link
Copy Markdown

@dylanhuff-at-coder dylanhuff-at-coder commented Apr 17, 2026

Adds a new SecretRequirements slice on preview.Output, populated by parsing data "coder_secret" "..." { ... } blocks in a template. Part of the User Secrets feature (PLAT-100); consumed by a companion PR in coder/coder that renders "missing required secret" diagnostics on the create-workspace page.

Notes

coder_secret doesn't currently exist as a Terraform data source yet. This PR still works because preview uses trivy's HCL parser for static analysis — it never runs terraform init on the template, so unknown data source types don't break extraction. The only test that does run terraform init is Test_VerifyE2E, and the two new testdata fixtures carry the repo's existing skipe2e sentinel file to opt them out of that test. The extraction tests (Test_Extract, Test_SecretRequirementErrors) all run normally and verify the behavior this PR adds.

A follow-up PR will need to remove the skipe2e sentinels once terraform-provider-coder ships the coder_secret data source, so E2E also covers these fixtures.

Also of note, this is the first of two PRs for PLAT-100. The second will be done in coder/coder and requires this one to be merged first, which is why I'd like to merge this even without the coder_secret data source existing.

@dylanhuff-at-coder dylanhuff-at-coder marked this pull request as ready for review April 17, 2026 22:41
Comment thread extract/secret.go
// SecretFromBlock decodes a `data "coder_secret" {}` Terraform block into a
// SecretRequirement. Exactly one of `env` or `file` must be set, and
// `help_message` is required. Returns (nil, diags) on validation failure.
func SecretFromBlock(block *terraform.Block) (*types.SecretRequirement, hcl.Diagnostics) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reccomend doing a panic recover guard:
https://github.com/coder/preview/blob/main/extract/preset.go#L13-L30

Things can panic in the type system pretty easily if misused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants