TF-via-PR icon indicating copy to clipboard operation
TF-via-PR copied to clipboard

Zip files not found on apply

Open slords opened this issue 1 month ago • 3 comments

Describe the bug

In my terraform I have a few zip files that are created and expected to be uploaded to S3. The plan works and shows all these ready for upload. Also a local apply works fine. However when I try and do an apply with this module I'm getting errors that the zip file can't be found. (ex. "monitor_oracle.zip: no such file or directory)

To Reproduce

add a data.archive_file resource to your project and try and do something with it (ex. upload to s3, use for lambda, etc).

Expected behavior

Zip file should be created and uploaded like it is when run locally.

slords avatar Nov 17 '25 15:11 slords

Thanks for raising, @slords, I think I might know what the underlying issue here is.

Workflow runs for plan and apply are completely isolated from each other, with only the plan-file being carried forward from plan into apply's run by TF-via-PR. As a result, any other interim build artifacts (e.g., zip archive) are not brought forward into apply, resulting in the "no such file or directory" error.

This is a bit of a tricky feature to implement.

  1. On the one hand, TF-via-PR could carry out a diff of files present both before and after plan to spot any additional files, and include them within the plan-file storage. Although, there's no guarantee the additional files will be within working-directory or it could be updating an existing file instead of creating a new one.
  2. On the other hand, TF-via-PR could implement a new build-artifacts input for users to explicitly list file paths for inclusion with the plan-file storage.

I reckon the second option is more appropriate/flexible, but requires the user to supply the artifact file paths ahead of time. This might not be feasible if the naming convention is random or time-dependent, rather than a static one.

Almost goes without saying, more than open to your thoughts, feedback and ideas on this thread.

rdhar avatar Nov 22 '25 12:11 rdhar

Raised #521 to document this feature/capability as "todo" as well as provide a (sub-standard) workaround whereby you can add arg-auto-approve: true so that apply rebuilds artifact(s) for provisioning.

rdhar avatar Nov 22 '25 12:11 rdhar

The build-artifacts would handle our needs, but I can see the issue with trying to determine what to save and pass on. What about being able to specify a directory, and all files that end up in that directory would be saved and passed on? This would require that the user have control over where things go.

The issue with doing a diff would be that you would want to exclude certain directories (.git, .terraform, etc), and knowing what directories to include vs exclude could be problematic.

I can use the arg-auto-approve: true for the time being. Does that check that a plan exists and is similar, or does this just skip that and run an apply and let it do its thing?

slords avatar Nov 22 '25 17:11 slords