Git-aware directory watching with Terraform

submited by
Style Pass
2021-07-08 19:30:09

Watching a directory with Terraform in order to update your resources is simple and brilliant! I’ve seen this done many times to do things like update lambda code or S3 bucket websites. The common way to accomplish this is zipping up a source folder with archive_file and then triggering a null_resource based on the output_sha . Here’s an example of that setup:

The problem with archive_file is that i t grabs everything in a directory, including things like node_modules or build logs. That means terraform plan will show spurious outputs, like when you do a new build or when a team member runs npm install on their own machine.

You can try to get around this by only zipping up strict source files (e.g. project/src ); but what about the top-level files like package.json ? In almost every language, there will be times that you have a combination of important and non-important files in the same directory.

In almost every language, there will be times that you have a combination of important and non-important files in the same directory.

Leave a Comment