Right now I have the following in my main.tf
:
resource "aws_lambda_function" "terraform_lambda" {
filename = "tf_lambda.zip"
function_name = "tf_lambda"
role = "lambda_basic_execution"
handler = "tf_lambda.lambda_handler"
source_code_hash = "${base64sha256(file("tf_lambda.zip"))}"
runtime = "python3.6"
}
My directory structure is like so:
.
|-- main.tf
|-- tf_lambda.zip
|-- tf_lambda
└── tf_lambda.py
When I run terraform apply
and then, in the console, go to the lambda created the code section is empty and it invites me to upload a zip file. How do I make sure the code actually gets uploaded?
You may also try this using archive_file, https://www.terraform.io/docs/providers/archive/d/archive_file.html So that when you run "terraform apply" the file will be re-zipped and uploaded.
data "archive_file" "zipit" {
type = "zip"
source_file = "tf_lambda/tf_lambda.py"
output_path = "tf_lambda.zip"
}
resource "aws_lambda_function" "terraform_lambda" {
function_name = "tf_lambda"
role = "lambda_basic_execution"
handler = "tf_lambda.lambda_handler"
filename = "tf_lambda.zip"
source_code_hash = "${data.archive_file.zipit.output_base64sha256}"
runtime = "python3.6"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With