fix: add JIT vendoring support to generate varfile and generate backend#2054
fix: add JIT vendoring support to generate varfile and generate backend#2054
Conversation
…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>
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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>
There was a problem hiding this comment.
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 aValidate() errormethod toVarfileOptionsand 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 writesbackend.tf.jsoninto 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>
|
These changes were released in v1.205.1. |
what
atmos terraform generate varfileandatmos terraform generate backendcommandswriteBackendConfigFile()to useconstructTerraformComponentWorkingDir()instead of hardcoded path construction, so backend files are written to the correct directory for JIT-vendored componentsensureTerraformComponentExists()helper that resolves the component path, checks existence, and triggers JIT provisioning viaAutoProvisionSourcewhen a source is configured"terraform"strings withcfg.TerraformComponentTypeconstantwriteBackendConfigFileworkdir support, and path construction with JIT vendored componentswhy
generate varfileandgenerate backendbypassed JIT provisioning because they calledProcessStacks()directly without triggering the provisioning hooks that download component sourceswriteBackendConfigFilehardcoded the component path (BasePath/Components.Terraform.BasePath/prefix/component) instead of usingconstructTerraformComponentWorkingDir(), which checks forWorkdirPathKeyset by JIT provisioningreferences
generate varfileandgenerate backenddon't work with JIT vendoring #2019Summary by CodeRabbit
New Features
Bug Fixes
Tests
Deprecations