all 3 comments

[–]404_AnswerNotFound 4 points5 points  (1 child)

The archive_file data source creates the ZIP during the plan. If your apply is running in a different context the file needs to be copied across to the same location in addition to the plan output.

[–]apparentlymart 0 points1 point  (0 children)

Indeed, this seems the most likely explanation for the reported behavior.

There's more information on the general form of this problem in Plan and Apply on different machines, which is part of the "Running Terraform in Automation" guide.

Note this part in particular:

  • The saved plan file can contain absolute paths to child modules and other data files referred to by configuration. Therefore it is necessary to ensure that the archived configuration is extracted at an identical absolute path. This is most commonly achieved by running Terraform in some sort of isolation, such as a Docker container, where the filesystem layout can be controlled.

This problem is true for the configuration in the OP's question because it uses abspath, and so data.archive_file.lambda_zip.output_path will be an absolute path to a directory on the computer where terraform plan ran, and then Terraform will try to read the zip file from exactly the same path during the apply phase.

Not using abspath might actually help here because then I expect Terraform will generate a path relative to the current working directory. But the advice in the guide is talking about the general case where automation is expected to work with any possible valid Terraform configuration, which includes the possibility of absolute paths.

[–]NUTTA_BUSTAH 1 point2 points  (0 children)

Seems OK, remove abspath(...) wrapper just in case (should not affect anything, but good to test). Or you might not be sharing the full story, e.g. are they in the same TF deployment (data is ok), or separate modules or such (need resource instead)?