terraform-aws-modules/terraform-aws-lambda

Extra quotes added from python packager

busla opened this issue · 2 comments

busla commented

Description

  • I have searched the open/closed issues and my issue is not listed.

Related #215

Versions

  • Module version: 3.3.1

  • Terraform version: 1.2.6

  • Terragrunt version: 0.38.6

  • Provider version(s):

provider "registry.terraform.io/hashicorp/aws" {
  version     = "4.25.0"
  constraints = ">= 4.9.0"
}

provider "registry.terraform.io/hashicorp/external" {
  version     = "2.2.2"
  constraints = ">= 1.0.0"
}

provider "registry.terraform.io/hashicorp/local" {
  version     = "2.2.3"
  constraints = ">= 1.0.0"
}

provider "registry.terraform.io/hashicorp/null" {
  version     = "3.1.1"
  constraints = ">= 2.0.0"
}

Reproduction Code [Required]

Using terragrunt and the jsonencode fix mentioned here #215

When using multiple source paths, the python packaging script seems to add extra double quotes before and after the paths.

Broken 1

  ...
  source_path = [
    jsonencode("${get_repo_root()}/../some/path/to/module"),
    jsonencode("${get_repo_root()}/../some/path/to/module/subdir"),
    {
      pip_requirements =     ...
    }
  ]
│ Could not locate source_path
│ ""/repo/root/../some/path/to/module"".

Note the extra double quotes from the python parser.

Broken 2

locals {
  ...
  python_source_path = jsonencode("${get_repo_root()}/../some/path/to/module")
}

...
  source_path = [
    local.python_source_path,
    "${local.python_source_path}/subdir",
    {
      pip_requirements =     ...
    }
  ]
│ Could not locate source_path
│ ""/repo/root/../some/path/to/module"/subdir".

Workaround

  ...
  source_path = [
    replace(jsonencode("${get_repo_root()}/../some/path/to/module"), "\"", ""),
    replace(jsonencode("${get_repo_root()}/../some/path/to/module/subdir"), "\"", ""),
    {
      pip_requirements =     ...
    }
  ]

If you are using Terragrunt, you should not use jsonencode() on each element inside source_path but instead you should use it on the whole value like this:

source_path = jsonencode([
    local.python_source_path,
    "${local.python_source_path}/subdir",
    {
      pip_requirements =     ...
    }
  ]
)

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.