title: How to trigger terraform to upload new lambda code
body: <p>I deploy lambda using Terraform as follows but have following questions:</p>
  
  <p>1) I want null_resource.lambda to be called always or when stop_ec2.py is changed so that stop_ec2_upload.zip is not out-of-date. What should I write in triggers{}?</p>
  
  <p>2) how to make aws_lambda_function.stop_ec2 update the new stop_ec2_upload.zip to cloud when stop_ec2_upload.zip is changed?</p>
  
  <p>right now I have to destroy aws_lambda_function.stop_ec2 then create it again. is there anything I can write in the code so that when I run terraform apply, 1) and 2) will happen automatically?</p>
  
  <pre><code>resource "null_resource" "lambda" {
    triggers {
     #what should I write here?
    }
  
    provisioner "local-exec" {
      command = "mkdir -p lambda_func &amp;&amp; cd lambda_py &amp;&amp; zip     
  ../lambda_func/stop_ec2_upload.zip stop_ec2.py &amp;&amp; cd .."
    }
  }
  resource "aws_lambda_function" "stop_ec2" {
      depends_on = ["null_resource.lambda"]
      function_name = "stopEC2"
      handler = "stop_ec2.handler"
      runtime = "python3.6"
      filename = "lambda_func/stop_ec2_upload.zip"
      source_code_hash =     
  "${base64sha256(file("lambda_func/stop_ec2_upload.zip"))}"
      role = "..."
  }
  </code></pre>