DevOps : AWS Lambda .zip with Terraform

Viewed 4166

I have written Terraform to create a Lambda function in AWS. This includes specifying my python code zipped. Running from Command Line into my tech box, all goes well. The terraform apply action sees my zip moved into AWS and used to create the lambda.

Key section of code :

resource "aws_lambda_function" "meta_lambda" {
              filename = "get_resources.zip"
              source_code_hash = filebase64sha256("get_resources.zip")
              .....

Now, to get this into other environments, I have to push my Terraform via Azure DevOps. However, when I try to build in DevOps, I get the following :

Error: Error in function call on main.tf line 140, in resource "aws_lambda_function" "meta_lambda": 140: source_code_hash = filebase64sha256("get_resources.zip") Call to function "filebase64sha256" failed: no file exists at get_resources.zip.

I have a feeling that I am missing a key concept here as I can see the .zip in the repo - so do not understand how it is not found by the build?

Any hints/clues as to what I am doing wrong, gratefully welcome.

enter image description here

3 Answers

Chaps, I'm afraid that I may have just been over my head here - new to terraform & DevOps !
I had a word with our (more) tech folks and they have sorted this.

The reason I think yours if failing is becuase the Tar Terraform step needs to use a different command line so it gets the zip file included into the artifacts. tar -cvpf terraform.tar .terraform .tf tfplan tar --recursion -cvpf terraform.tar --exclude='/.git' --exclude='.gitignore' .

.. it that means anything to you ! Whatever they did, it works !

As there is a bounty on this, I still going to assign it as I am grateful for the input ! Sorry if this was a it of a newbie error.

You can try building your package with terraform AWS lambda build module. As it has been very useful for the processTerraform Lambda build module

According to the document example, in the source_code_hash argument, filebase64sha256 ("get_resources.zip") needs to be enclosed in double quotes.

enter image description here

You can refer to this document for details.

Related