terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
885 stars 658 forks source link

patterns in source_path do not work as expected unless negated #546

Closed reikje closed 2 months ago

reikje commented 4 months ago

Description

I have the following project structure.

.
├── Dockerfile
├── README.md
├── poetry.lock
├── pyproject.toml
├── src
│   └── function1
│       └── __init__.py
│       └── app.py
│   └── function2
│       └── __init__.py
│       └── app.py
│   └── function3
│       └── __init__.py
│       └── app.py
│   └── shared
│       └── __init__.py
│       └── utils.py
│   └── requirements.txt
├── terraform
│   └── sandbox
│       └── main.tf
│   └── common
│       └── main.tf
└── tests
    └── __init__.py

Trying to build a package for each individual function by specifying the modules and files that should make it into the zip. I don't get this work - everything is always included. When I negate the pattern however, I can see that the module is properly excluded.

Versions

Terraform v1.6.1 on darwin_amd64

Reproduction Code [Required]

module "lambda_function" {
  source                            = "terraform-aws-modules/lambda/aws"
  version                           = "7.2.1"
  timeout                           = 300
  function_name              = "function1"
  handler                           = "function1.app.handler"
  runtime                           = "python3.12"
  create_sam_metadata               = true
  publish                           = true
  hash_extra                        = "function1"
  source_path                       = [
    {
      path = "${path.module}/../../src"
      patterns = [
        "function1\\/.*",
        "requirements.txt",
      ]
    }
  ]
}

Steps to reproduce the behavior:

Expected behavior

When packaging during terraform apply it should only package these items:

├── src
│   └── function1
│       └── __init__.py
│       └── app.py
│   └── requirements.txt

Actual behavior

Everything under src is packaged.

pavitra-infocusp commented 4 months ago

Try checking the build plans that are generated under the builds dir. It should give you an idea of which files are packaged.

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 2 months ago

This issue was automatically closed because of stale in 10 days

github-actions[bot] commented 1 month ago

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.