Skip to content

feat: add archive_path attribute to coderd_template versions#344

Open
jatcod3r wants to merge 3 commits intocoder:mainfrom
jatcod3r:add-archive-path
Open

feat: add archive_path attribute to coderd_template versions#344
jatcod3r wants to merge 3 commits intocoder:mainfrom
jatcod3r:add-archive-path

Conversation

@jatcod3r
Copy link
Copy Markdown

@jatcod3r jatcod3r commented May 3, 2026

Implements #340. Adds archive_path as an alternative to directory in the versions block of coderd_template, supporting .tar and .zip files.

Changes:

  • Add archive_path (Optional) and archive_hash (Computed) attributes
  • Validator ensures exactly one of directory/archive_path is set
  • Plan modifier computes archive_hash from file contents (SHA-256)
  • normalizeZip adds missing directory entries for archives produced by Terraform's archive_file data source
  • uploadArchive sends the archive to Coder with correct content type
  • Warn when switching between archive_path and directory about hidden file inclusion differences
  • Document 100 MiB server upload limit in archive_path description

Tests:

  • TestComputeArchiveHash (4 cases)
  • TestArchiveContentType (5 cases)
  • TestNormalizeZip (2 cases)
  • TestReconcileVersionIDs extended with ArchiveHashMatching/Changed

@jatcod3r jatcod3r self-assigned this May 3, 2026
Implements coder#340. Adds archive_path as an alternative to directory in the
versions block of coderd_template, supporting .tar and .zip files.

Changes:
- Add archive_path (Optional) and archive_hash (Computed) attributes
- Validator ensures exactly one of directory/archive_path is set
- Plan modifier computes archive_hash from file contents (SHA-256)
- normalizeZip adds missing directory entries for archives produced by
  Terraform's archive_file data source
- uploadArchive sends the archive to Coder with correct content type
- Warn when switching between archive_path and directory about hidden
  file inclusion differences
- Document 100 MiB server upload limit in archive_path description

Tests:
- TestComputeArchiveHash (4 cases)
- TestArchiveContentType (5 cases)
- TestNormalizeZip (2 cases)
- TestReconcileVersionIDs extended with ArchiveHashMatching/Changed
@jatcod3r jatcod3r force-pushed the add-archive-path branch from 7824c8c to 1f8930d Compare May 3, 2026 23:00
@ethanndickson ethanndickson self-requested a review May 7, 2026 02:53
@ethanndickson
Copy link
Copy Markdown
Member

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f8930debf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/provider/template_resource.go Outdated
Comment on lines +1003 to +1005
dirSet := !version.Directory.IsNull()
archiveSet := !version.ArchivePath.IsNull()
if !dirSet && !archiveSet {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Ignore unknown source attrs in versions validator

The new directory/archive_path XOR check treats any non-null value as "set", but unknown values are non-null in the framework, so a configuration where these attributes are conditionally computed can fail validation early with a false "mutually exclusive" or "must be specified" error. Terraform’s framework guidance is to avoid emitting validation errors for unknown non-computed values and wait for the later known pass; otherwise valid plans can be blocked before dependencies are resolved.

Useful? React with 👍 / 👎.

Per Terraform framework guidance, validators should not emit errors for
unknown values. When either directory or archive_path is unknown (e.g.,
referencing a computed value from another resource), the XOR check is
skipped. Terraform will re-run validators once values resolve during
apply.
@jatcod3r
Copy link
Copy Markdown
Author

jatcod3r commented May 7, 2026

@codex review

@coder coder deleted a comment from chatgpt-codex-connector Bot May 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a48a37f432

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1467 to +1468
tflog.Info(ctx, "skipping vars file discovery for archive upload, use tf_vars to provide variables")
} else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore tfvars discovery for archive uploads

The archive_path branch skips vars-file discovery entirely, so UserVariableValues are only populated from explicit tf_vars. In contrast, the directory flow still parses terraform.tfvars/*.auto.tfvars before creating the template version. This means switching an existing template from directory to archive_path can silently drop variable values and cause import/job failures when required variables were previously sourced from vars files.

Useful? React with 👍 / 👎.

Comment thread internal/provider/template_resource.go Outdated
Comment on lines +1280 to +1283
dir := filepath.Dir(f.Name)
for dir != "." && dir != "/" && dir != "" {
dirEntry := dir + "/"
if existingDirs[dirEntry] || missingDirs[dirEntry] {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use slash-path handling when deriving ZIP directories

normalizeZip derives directory entries with filepath.Dir, which is OS-specific. On Windows, this can produce backslash-based path segments while ZIP entry names are forward-slash based, leading to synthesized directory names that do not match archive paths and leaving nested entries effectively unnormalized.

Useful? React with 👍 / 👎.

- Use stdpath.Dir (stdlib path package) instead of filepath.Dir when
  traversing ZIP entry names. ZIP entries always use forward slashes per
  spec, and filepath.Dir is OS-specific (would produce backslashes on
  Windows).

- Enhance the directory-to-archive_path switch warning to also mention
  that automatic tfvars file discovery is not performed for archive
  uploads, directing users to use tf_vars explicitly.
@jatcod3r
Copy link
Copy Markdown
Author

jatcod3r commented May 7, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

3 participants