Panfactum / stack

The Panfactum Stack
https://panfactum.com
Other
16 stars 5 forks source link

fix: ensure script is not run if the folder doesn't exist #168

Closed mschnee closed 1 month ago

mschnee commented 1 month ago

After updating the panfactum flake to edge.24-10-23 we noticed extremely verbose error messages attempting to apply a plan

realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory
realpath: ./packages/infrastructure: No such file or directory
find: '': No such file or directory

This came from the invocation of pf-get-local-module-hash, which is on the truthy side of a ternary expression local.pf_stack_version == "local" ? run_cmd() : ""

I suspect that terraform/terragrunt/opentofu needs to evaluate the entire result set before evaluating the condition. this can be seen by changing the results like so:

pf_stack_local_ref                     = local.pf_stack_version != "local" ? run_cmd("--terragrunt-global-cache", "--terragrunt-quiet", "pf-get-local-module-hash", "${local.pf_stack_local_path}/packages/TRUTHY") : run_cmd("--terragrunt-global-cache", "--terragrunt-quiet", "pf-get-local-module-hash", "${local.pf_stack_local_path}/packages/FALSY")

resulting in

find: '.../packages/TRUTHY': No such file or directory
find: '.../packages/FALSY': No such file or directory

Given that this lookup we aren't checking the stack out locally, a simple change to also test for the existence of the input string as a directory should suffice.

fullykubed commented 1 month ago

You are correct in identifying the issue. We have a fix in the next release.

We preferred to have the fix in the panfactum.hcl rather than in the script as the script should definitely still error if given a non-existent directory.