terraform-provider-archive icon indicating copy to clipboard operation
terraform-provider-archive copied to clipboard

Using multiple source files for Lambda with archive_file

Open sanspace opened this issue 5 years ago • 4 comments

Terraform Version

Terraform v0.12.15
+ provider.archive v1.3.0
+ provider.aws v2.37.0

Affected Resource(s)

archive_file

Terraform Configuration Files

data "archive_file" "lambda" {
  type        = "zip"
  source_dir  = "../src/"
  output_path = "../dist/lambda_src.zip"
}

Expected Behavior

archive should contain only the files.

Actual Behavior

archive has a directory that contains the files

Steps to Reproduce

Use the example with more than one source file.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

  • Using multiple source files for Lambda with archive_file

TF example with just one file: https://github.com/terraform-providers/terraform-provider-aws/blob/master/examples/lambda/main.tf#L8-L12 In my case, it's more than one source file.

sanspace avatar Nov 18 '19 20:11 sanspace

Have you checked using the CLI? If on macOS it adds the folder.

unzip -vl lambda_function_payload.zip

gurre avatar Mar 04 '20 19:03 gurre

Have we put any consideration into this. I have this same issue with Lambda creations. There are packages being zipped but I also need to add my handler.py into the same zip - but can't seem to do so with this provider.

I thought this might be a common use-case does anyone have a work around?

Otherwise i'll be forced to use local-exec (which is not ideal)

AzySir avatar Aug 17 '21 12:08 AzySir

Seems like a reasonable use case, I have a handler in dist (compiled from ts) and some packages in node_modules. Doesn't seem crazy to want to package them up into the same zip.

jcollum avatar Sep 07 '21 23:09 jcollum

Any chance to get this implemented?

simonweil avatar Jul 05 '22 08:07 simonweil

@sanspace can I confirm that this is still an issue with the latest version of the provider?

When using v2.2.0 with the following configuration:

data "archive_file" "lambda" {
  type        = "zip"
  source_dir  = "src/"
  output_path = "dist/lambda_src.zip"
}

If the source_dir contains the following:

-rw-r--r--  1 bdb  staff   14 15 Aug 14:12 file1.txt
-rw-r--r--  1 bdb  staff   14 15 Aug 14:12 file2.txt
-rw-r--r--  1 bdb  staff   14 15 Aug 14:12 file3.txt

Running terraform apply generates lambda_src.zip in the dist directory.

Running unzip lambda_src.zip in the dist directory then produces the following:

-rw-r--r--  1 bdb  staff   14  1 Jan  2049 file1.txt
-rw-r--r--  1 bdb  staff   14  1 Jan  2049 file2.txt
-rw-r--r--  1 bdb  staff   14  1 Jan  2049 file3.txt
-rw-r--r--  1 bdb  staff  412 16 Nov 15:56 lambda_src.zip

The archive (zip) did not contain a directory containing the files but just contains the files. Can you confirm that you are seeing something different from this? Thanks.

bendbennett avatar Nov 16 '22 16:11 bendbennett

@bendbennett I left the org years back and I no longer have the same set up. If you do not see any issues, please go ahead and close this one. Thank you!

sanspace avatar Dec 16 '22 10:12 sanspace

@sanspace thanks for letting me know.

I'm going to close this as I cannot reproduce the original issue.

bendbennett avatar Dec 16 '22 12:12 bendbennett

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar May 23 '24 13:05 github-actions[bot]