Skip to content

Enhancement | Hermetic bats tests for the tofu/terraform layer lifecycle - #347

Merged
diego-ojeda-binbash merged 1 commit into
masterfrom
feature/hermetic-tofu-bats
Nov 14, 2026
Merged

diego-ojeda-binbash merged 1 commit into
masterfrom
feature/hermetic-tofu-bats

Conversation

@diego-ojeda-binbash

Copy link
Copy Markdown
Contributor

What?

  • Adds tests/bats/leverage_tofu_lifecycle.bats: 10 tests that run init → plan → apply → output → destroy against the real tofu and terraform binaries, with no cloud access. The layers use the local backend and the built-in terraform_data resource.
  • Adds the _create_local_backend_project helper to tests/bats/utils.bash.
  • No CLI code changes. No CI changes either: make test-int already picks up every file under tests/bats, and the job already installs tofu and terraform.

The tests cover:

Area What is checked
Lifecycle plan -detailed-exitcode exits 2 → 0 → 2 around apply/destroy, and the CLI passes it through. Runs with tofu and with terraform
Injection common.tfvars + account.tfvars reach the layer (output ts-account-first); -backend-config is applied (the state lands at the path from backend.tfvars)
--layers Layers run in the given order, and the run stops at the first failing layer
Usage errors --layers inside a layer, a missing layer, and the layout validation on init all exit 1
Auth With SSO and MFA off, no AWS config or credentials are written. HOME is isolated in a temp dir

The new file adds ~12 s to the bats job.

Why?

H5 in #346. The unit tests mock TFRunner.run, and the ref-arch E2E needs AWS secrets, so it skips forks. Until now, nothing ran the real init/plan/apply cycle or --layers on every PR.

To check the tests catch real breakage, I dropped the tfvars and -backend-config injection from tf.py: 6 of the 10 tests fail. The other 4 cover error paths that do not depend on injection.

Notes

  • On macOS, leverage terraform init fails when the project path crosses a symlink ($TMPDIR is under /var → /private/var). Terraform turns the -backend-config path into a relative one from the real cwd, and ends up one ../ short. Tofu is not affected. The helper resolves the path with pwd -P. Linux CI is not affected either.

Relates to #346

🤖 Generated with Claude Code

Run init, plan, apply, output and destroy against the real binaries, on a
single layer and with --layers, with no cloud access: the layers use the
local backend and the built-in terraform_data resource.

Covers exit code passthrough (-detailed-exitcode), tfvars and backend
config injection, --layers order and fail-fast, the usage errors, and that
no AWS credentials are touched when SSO and MFA are off.

Relates to #346 (H5).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@diego-ojeda-binbash diego-ojeda-binbash added enhancement New feature or request test labels Nov 14, 2026
@coderabbitai

coderabbitai Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19447566-9c75-4f76-b8db-21e9c9da5778
Commits

Reviewing files that changed from the base of the PR and between 8b20f95 and eaeac2a.

Files selected for processing: 2

  • tests/bats/leverage_tofu_lifecycle.bats
  • tests/bats/utils.bash
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@diego-ojeda-binbash diego-ojeda-binbash self-assigned this Nov 14, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 43610001772

Coverage remained the same at 67.689%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4070
Covered Lines: 2898
Line Coverage: 71.2%
Relevant Branches: 1080
Covered Branches: 588
Branch Coverage: 54.44%
Branches in Coverage %: Yes
Coverage Strength: 0.71 hits per line

💛 - Coveralls

@diego-ojeda-binbash
diego-ojeda-binbash merged commit 859cc76 into master Nov 14, 2026
21 of 23 checks passed
@diego-ojeda-binbash
diego-ojeda-binbash deleted the feature/hermetic-tofu-bats branch November 14, 2026 15:34
@diego-ojeda-binbash

Copy link
Copy Markdown
Contributor Author

Sabotage check in CI: #348 (closed, not merged) dropped the tfvars and -backend-config injection from tf.py on top of this branch.

Result in integration_tests: red, 6 of the 10 new tests fail, the same as locally:

  • not ok 10 Runs the full lifecycle of a layer
  • not ok 11 Injects the common and account tfvars
  • not ok 12 Injects the backend config on init
  • not ok 13 Does not touch AWS credentials when SSO and MFA are off
  • not ok 14 Applies several layers in the given order
  • not ok 19 Runs the full lifecycle of a layer with terraform

The 4 that kept passing (15–18) cover error paths that do not depend on the injection. The ref-arch E2E triggered by that PR was cancelled before it reached AWS.

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

Labels

enhancement New feature or request test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants