Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request][archive_file] Allow source_file to be list of files #8565

Closed
mtougeron opened this issue Aug 31, 2016 · 5 comments
Closed

Comments

@mtougeron
Copy link
Contributor

Hi, it would be nice if the archive_file resource allowed source_file and source_dir to be lists. It would also be nice if they were not mutually exclusive.

For example, I'd like to use the following config to support my aws lambda functions.

resource "archive_file" "sesbounce" {
  type = "zip"
  source_file = [
    "${path.module}/sesbounce.py",
    "${path.module}/shared/common.py"
  ]
  source_dir = [
    "${path.module}/pip_modules/"
  ]

  output_path = "${path.module}/_files/sesbounce.zip"
}

resource "aws_lambda_function" "sesbounce" {
  filename = "${path.module}/_files/sesbounce.zip"
  function_name = "sesbounce"
  role = "${aws_iam_role.iam_for_lambda.arn}"
  handler = "sesbounce.handler_ses_bounce"
  source_code_hash = "${base64sha256(file("_files/sesbounce.zip"))}"
}
@Ninir
Copy link
Contributor

Ninir commented Aug 31, 2016

I would like to augment @mtougeron idea with the following, which would make the archive resource even more powerful & flexible.

We could benefit from 2 new attributes in order to handle more cases:

  • append_files list of files to include
  • exclude_files, list of files to exclude
Use-case 1: Include files from multiple paths

Let's say you need to deploy a lambda to 2 different environments: dev and prod. This lambda aims to send data to a Google Service. You then need credentials that are different between the dev & prod.
Embedding the 2 files is a security issue (a developer in the dev env could gain access to the prod one) so a no-go in this case.

An idea to handle this would be to dynamically add the appropriate config file in the archive, following this:

resource "archive_file" "init" {
    type = "zip"
    source_content_filename = "${path.module}/init.tpl"
    output_path = "${path.module}/files/init.zip"
    source_dir = "../mycode"
    append_files = [
        "../myconfig/config-${myenv}"
    ]
}
Use-case 2: Exclude files from an archive (for instance to reduce the total size of the archive)

Let's say you're doing some Python in your Lambda and you want to exclude some library files (boto3, pip binaries if using virtualenvs, etc.)

The use-case would match this:

resource "archive_file" "init" {
    type = "zip"
    source_content_filename = "${path.module}/init.tpl"
    output_path = "${path.module}/files/init.zip"
    source_dir = "../mycode"
    exclude_files = [
        "../mycode/bin",
        "../mycode/lib/boto3",
        "../mycode/env/lib/python2.7/site-packages/pip"
    ]
}

What do you guys think?

@stumyp
Copy link

stumyp commented Oct 1, 2016

👍
Or, if possible allow to provide directory name instead of file name, so it creates archive out of all directory instead.

Thank you

@Ninir
Copy link
Contributor

Ninir commented Oct 2, 2016

@stumyp this is already the case as far as I understand what you meant :)

@w32-blaster
Copy link
Contributor

Would be great to have list of files/dirs.

@ghost
Copy link

ghost commented Apr 10, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants