Skip to content

fix: add JIT vendoring support to generate varfile and generate backend#2054

Merged
aknysh merged 3 commits intomainfrom
aknysh/fix-generate-varfile-generate-backend
Feb 4, 2026
Merged

fix: add JIT vendoring support to generate varfile and generate backend#2054
aknysh merged 3 commits intomainfrom
aknysh/fix-generate-varfile-generate-backend

Conversation

@aknysh
Copy link
Member

@aknysh aknysh commented Feb 4, 2026

what

  • Add JIT (Just-In-Time) vendoring support to atmos terraform generate varfile and atmos terraform generate backend commands
  • Fix writeBackendConfigFile() to use constructTerraformComponentWorkingDir() instead of hardcoded path construction, so backend files are written to the correct directory for JIT-vendored components
  • Add ensureTerraformComponentExists() helper that resolves the component path, checks existence, and triggers JIT provisioning via AutoProvisionSource when a source is configured
  • Replace hardcoded "terraform" strings with cfg.TerraformComponentType constant
  • Add comprehensive unit tests for all new helper functions, writeBackendConfigFile workdir support, and path construction with JIT vendored components

why

  • generate varfile and generate backend bypassed JIT provisioning because they called ProcessStacks() directly without triggering the provisioning hooks that download component sources
  • writeBackendConfigFile hardcoded the component path (BasePath/Components.Terraform.BasePath/prefix/component) instead of using constructTerraformComponentWorkingDir(), which checks for WorkdirPathKey set by JIT provisioning
  • This meant both commands failed for any component that relied on source vendoring, as the component directory didn't exist yet and the backend file was written to the wrong path

references

Summary by CodeRabbit

  • New Features

    • Just-in-time provisioning for Terraform components when missing (5-minute timeout).
    • Terraform component type made configurable for generation commands.
  • Bug Fixes

    • Improved working-directory and varfile path resolution, including vendored/JIT component scenarios.
    • Stronger component-existence validation with clearer, contextual errors.
  • Tests

    • Extensive new unit/integration tests for varfile/backend generation, JIT provisioning, permission/error cases, and deprecated command behavior.
  • Deprecations

    • Legacy generate commands now signal deprecation with explicit errors.

…nd commands

Both `generate varfile` and `generate backend` bypassed JIT provisioning,
failing for components that rely on source vendoring. This adds
`ensureTerraformComponentExists()` which resolves the component path,
checks existence, and triggers JIT provisioning when a source is
configured. Also fixes `writeBackendConfigFile()` to use
`constructTerraformComponentWorkingDir()` instead of hardcoded path
construction, so JIT-vendored components with a workdir path are
handled correctly.

Closes #2019

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@aknysh aknysh requested a review from a team as a code owner February 4, 2026 21:15
@aknysh aknysh added the patch A minor, backward compatible change label Feb 4, 2026
@aknysh aknysh self-assigned this Feb 4, 2026
@aknysh aknysh added the patch A minor, backward compatible change label Feb 4, 2026
@github-actions github-actions bot added the size/l Large size PR label Feb 4, 2026
@github-actions
Copy link

github-actions bot commented Feb 4, 2026

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds workdir-aware path resolution and JIT provisioning to terraform generate varfile/backend flows, plus helpers to verify/provision Terraform components on demand. Commands now use configurable component type/CLI args. Extensive tests validate varfile/backend paths, JIT provisioning, and filesystem error handling.

Changes

Cohort / File(s) Summary
Path utils tests
internal/exec/path_utils_test.go
Adds tests for varfile/workdir resolution with JIT-vendored components and explicit workdir paths; diff contains duplicated test blocks.
Varfile generation impl & tests
internal/exec/terraform_generate_varfile.go, internal/exec/terraform_generate_varfile_test.go, internal/exec/terraform_generate_varfile_unix_test.go
Adds helpers checkDirectoryExists, ensureTerraformComponentExists, tryJITProvision; integrates JIT provisioning into ExecuteGenerateVarfile; replaces hard-coded component type/CLI args with config values; adds broad unit/integration tests including permission/error scenarios.
Backend generation impl & tests
internal/exec/terraform_generate_backend.go, internal/exec/terraform_generate_backend_test.go
Calls ensureTerraformComponentExists before backend validation; uses workdir-aware backend file path resolution; replaces hard-coded component type with config value; adds tests for deprecated command, backend file writing across path scenarios, and backend-type validation edge cases.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Cmd
    participant CompCheck
    participant JIT
    participant FS

    Client->>Cmd: invoke "terraform generate varfile/backend"
    Cmd->>CompCheck: ensureTerraformComponentExists(componentInfo)
    CompCheck->>FS: checkDirectoryExists(componentPath)
    alt component exists
        FS-->>CompCheck: exists
        CompCheck-->>Cmd: OK
    else component missing
        CompCheck->>JIT: tryJITProvision(source, timeout)
        JIT->>FS: provision component (clone/provide workdir)
        FS-->>JIT: provisioned / error
        JIT-->>CompCheck: result
        CompCheck->>FS: re-check componentPath (including workdir)
        FS-->>CompCheck: exists / not found
        CompCheck-->>Cmd: OK / error
    end
    Cmd->>FS: resolve workdir-aware path & write file
    FS-->>Cmd: file written / error
    Cmd-->>Client: return success / error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • osterman
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding JIT vendoring support to generate varfile and generate backend commands.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #2019 by adding JIT provisioning support, using component path functions, and ensuring commands work with JIT-vendored components.
Out of Scope Changes check ✅ Passed All changes directly support JIT vendoring: helper functions, component validation, path construction, test coverage, and hardcoded string replacement align with stated objectives.
Docstring Coverage ✅ Passed Docstring coverage is 86.11% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aknysh/fix-generate-varfile-generate-backend

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 71.11111% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.71%. Comparing base (802e656) to head (39012b5).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/terraform_generate_varfile.go 72.50% 6 Missing and 5 partials ⚠️
internal/exec/terraform_generate_backend.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2054      +/-   ##
==========================================
+ Coverage   75.66%   75.71%   +0.04%     
==========================================
  Files         793      793              
  Lines       73953    73990      +37     
==========================================
+ Hits        55960    56022      +62     
+ Misses      14497    14473      -24     
+ Partials     3496     3495       -1     
Flag Coverage Δ
unittests 75.71% <71.11%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/exec/terraform_generate_backend.go 85.71% <60.00%> (+8.52%) ⬆️
internal/exec/terraform_generate_varfile.go 82.89% <72.50%> (+9.21%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add integration tests using stack-templates fixture to exercise full
ExecuteGenerateVarfile and ExecuteGenerateBackend code paths through
ProcessStacks. Add error-path tests for ProcessStacks failures.

Coverage improvements:
- ExecuteGenerateVarfile: 0% -> 84.2%
- ExecuteGenerateBackend: 0% -> 76.5%

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
osterman
osterman previously approved these changes Feb 4, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@internal/exec/terraform_generate_backend_test.go`:
- Around line 212-213: The first line of the multiline comment above the
TestExecuteGenerateBackend_ProcessStacksFails test is missing a trailing period
and fails the godot linter; update the comment for the test (referenced by
TestExecuteGenerateBackend_ProcessStacksFails and ExecuteGenerateBackend) to end
the first line with a period so the multiline comment conforms to the project's
comment punctuation rules.

In `@internal/exec/terraform_generate_varfile_test.go`:
- Around line 276-277: The multiline comment above the
TestTryJITProvision_WithSourceURI test (and other test comment blocks
referenced) has lines that do not end with periods, which fails the godot
linter; edit the comment text for TestTryJITProvision_WithSourceURI (and the
other affected test comments near the referenced ranges) so that every line ends
with a period, ensuring each sentence in the block comment terminates with a
period.
- Around line 417-419: The tests call os.Getuid (permission tests) which is
unavailable on Windows; move those permission-related tests from the current
file into a new *_unix_test.go file and add the build constraint //go:build
!windows (or // +build !windows) at the top so they only compile on Unix-like
systems; update both occurrences of the os.Getuid usage (the existing permission
test and the other similar check) so they reside in that Unix-only test file.
🧹 Nitpick comments (2)
internal/exec/terraform_generate_varfile_test.go (2)

134-188: These tests are tautological; they don’t exercise production behavior.
They only re-check struct field values. Consider adding a Validate() error method to VarfileOptions and test that, or drop these tests.

As per coding guidelines: “Test behavior, not implementation — Avoid tautological tests.”

Also applies to: 329-344


571-605: Avoid mutating the shared fixture directory without cleanup.
This test writes backend.tf.json into the fixture. Add cleanup or use a temp copy to keep tests isolated.

✅ Minimal cleanup option
 backendFile := filepath.Join(fixtureDir, "components", "terraform", "mock", "backend.tf.json")
+t.Cleanup(func() { _ = os.Remove(backendFile) })
 assert.FileExists(t, backendFile)
 content, err := os.ReadFile(backendFile)

- Move permission tests (os.Getuid/os.Chmod) to _unix_test.go with build tag
- Remove tautological tests that only re-check struct field values
- Use filepath.Join for all path config values instead of forward slashes
- Add t.Cleanup for backend integration test fixture file
- Fix godot linter comments

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@aknysh aknysh requested a review from osterman February 4, 2026 23:17
@aknysh aknysh merged commit 63742eb into main Feb 4, 2026
56 checks passed
@aknysh aknysh deleted the aknysh/fix-generate-varfile-generate-backend branch February 4, 2026 23:24
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

These changes were released in v1.205.1.

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

Labels

patch A minor, backward compatible change size/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generate varfile and generate backend don't work with JIT vendoring

2 participants