We have several developers, each deploying a lambda function (from their own computer) via terraform to a shared account. Terraform state files are in an S3 bucket for consistency. As we're deploying from different computers, the function zipfile may not exist locally. How can I make sure the function zip is always created?
I'm using the following code in a terraform module
resource "null_resource" "zipfile" {
depends_on = [null_resource.code_dependencies]
provisioner "local-exec" {
command = "cd ${var.source_dir} && zip -r function.zip * -x *.zip"
}
}
resource "aws_lambda_function" "function" {
depends_on = [null_resource.zipfile]
filename = "${var.source_dir}/function.zip"
function_name = var.function_name
role = aws_iam_role.lambda_function_role.arn
handler = var.handler
source_code_hash = filesha256("${var.source_dir}/function.zip")
runtime = var.runtime
}