Repository navigation
Fix | tf: init --layers backend key per layer, validate-layout exit code + error path tests - #385
Conversation
…ode + error path tests - init --layers, from the account or a layers-group directory and without --skip-validation, wrote the same backend key to every new layer, built from cwd instead of the layer (e.g. account/us-east-1/terraform.tfstate), so the layers would share one state. The key now follows each layer's path. - validate-layout exited 0 even when a check failed: click drops the command's return value. It now exits 1. - Tests for the --layers errors, init on an invalid layout, the backend key that init writes, _make_layer_backend_key and validate-layout. tf.py coverage goes from 87% to 99%. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughThe Terraform module now generates multi-layer backend state keys from each layer’s project-relative path. It also exits with status 1 when layout validation fails. Tests cover these behaviors and related layer-selection cases. ChangesTerraform module behavior
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related issues
Possibly related PRs
Suggested reviewers: Merge Risk:
|
|
@claude review |
Coverage Report for CI Build 44634027715Coverage increased (+1.9%) to 79.947%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
|
@coderabbitai review |
Action performed
|
What?
init --layersbackend key (leverage/modules/tf.py): when a layer'sconfig.tfhas nokey,initwrites one. It was built from cwd, not the layer. Run from the account or a layers-group directory with--layers(and without--skip-validation), every new layer got the same key, e.g.account/us-east-1/terraform.tfstatefor bothsecurity-baseandbase-tf-backend, so they would share one state. The key now follows each layer's path. The bug dates from Issue 141 s3 key multi region support #149.validate-layoutexit code: it exited 0 even when a check printed✘ FAILED, since click drops the command's return value. It now exits 1, so it can be used in scripts and CI.tests/test_modules/test_tf.py, 19 new):--layerserrors: inside a layer, missing flag, outside an account, a layer that doesn't exist. None runs the binary.initstops on an invalid layout before running anything.initwrites, from a layer and with--layers._make_layer_backend_key: region,global,base-/tools-prefixes,tf-↔terraform-,-drsuffix.validate-layout: ok, noenvironment, wrong backend key, wrongbackend.tfvars, account directory name mismatch.Why?
H7 in #346:
CliRunnertests fortf, always assertingexit_code. Exit code propagation and--layersordering were already covered; this adds the error paths.tf.pycoverage goes from 87% to 99% (onlyrefresh-credentialsis left; auth has its own tests).Run against
master'stf.py, 3 of the new tests fail: the two bugs above.Checks
References
tfpart; theprojectpart waits for Feature | Project create extra checks #334)🤖 Generated with Claude Code
Summary by CodeRabbit
validate-layoutnow exits with a failure status when validation fails, so failed checks are reported correctly.