fix(scripts): generate the tofu test inside the module directory - #27
Merged
Conversation
setup-layer wrote the generated .tftest.hcl to
deployment/tests/{type}/{name}/, but run_tofu_tests.sh runs `tofu test`
from whichever directory holds the file. That directory contains no .tf
files, so the generated test ran against an empty module and asserted
nothing. All seven existing tofu tests live in {type}/{name}/modules/.
Write it to modules/ instead, and keep creating the tests/ directory for
the BATS unit tests that belong there.
Also add a consistency check between the scope-configuration schema and
the layer tree. layer_executor resolves an implementation by joining the
configured value straight onto deployment/{type}/{value}/setup, so any
value the schema offers that has no matching directory fails only at the
first deployment. This is the class of bug that let the azure_distribution
enum drift to blob_cdn while the directory was blob-cdn.
gdrojas
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
setup-layerwrites the generated.tftest.hcltodeployment/tests/{type}/{name}/, butrun_tofu_tests.shrunstofu testfrom whichever directory holds the file:That directory has no
.tffiles in it, so the generated test runs against an empty module and asserts nothing. All seven tofu tests that exist today live in{type}/{name}/modules/, next to the code they exercise.You hit this the first time you scaffold a new layer, which makes it easy to ship a layer that looks tested and is not.
Change
.tftest.hcltomodules/instead. Thetests/{type}/{name}/directory is still created, since that is where the BATS unit test for the setup script belongs.Regression coverage
Two new BATS files, 12 tests, all passing.
tests/scripts/setup-layer_test.batscovers the generator itself: test placement, module scaffolding, name normalization, and argument handling. It runs the script inside a temp directory, so it writes nothing into the repo.tests/specs/layer_selection_test.batschecks the scope-configuration schema against the layer tree.layer_executorresolves an implementation by joining the configured value straight onto a path:setup_script="$SERVICE_PATH/deployment/${LAYER_TYPE}/${layer_value}/setup"So every value the schema offers must exist as a directory with that exact name. A mismatch is invisible until the first deployment fails with
Unknown implementation. This is the class of bug that let theazure_distributionenum drift toblob_cdnwhile the directory wasblob-cdn, fixed separately in 895246e.Verified the check actually fails on that case by reintroducing it temporarily:
Testing
Follow-up, not in this PR
The generated boilerplate uses
mock_provider "${LAYER_NAME}", which is only right by coincidence. Thecloudfrontlayer mocksaws, andblob-cdnmocksazurerm. Worth turning into a TODO placeholder so nobody copies it as-is.🤖 Generated with Claude Code