I try to implement aws lambda function using terraform.
I simply have null_resource
that have local provisioner and resource.archive_file
that zips source code after all preparation is done.
resource "null_resource" "deps" {
triggers = {
package_json = "${base64sha256(file("${path.module}/src/package.json"))}"
}
provisioner "local-exec" {
command = "cd ${path.module}/src && npm install"
}
}
resource "archive_file" "function" {
type = "zip"
source_dir = "${path.module}/src"
output_path = "${path.module}/function.zip"
depends_on = [ "null_resource.deps" ]
}
Recent changes to Terraform deprecated resource.archive_file
, so data.archive_file
should be used instead. Unfortunately, data
executes before resources, and so local provisioner from dependent resource is called way after zip is created. So code bellow does not produce warning any more, however not working at all.
resource "null_resource" "deps" {
triggers = {
package_json = "${base64sha256(file("${path.module}/src/package.json"))}"
}
provisioner "local-exec" {
command = "cd ${path.module}/src && npm install"
}
}
data "archive_file" "function" {
type = "zip"
source_dir = "${path.module}/src"
output_path = "${path.module}/function.zip"
depends_on = [ "null_resource.deps" ]
}
Am I missing something? What is correct way to do this with recent versions.
Terraform: v0.7.11 OS: Win10
working_dir
option instead of prefixing it withcd
. – Yep_It's_Me