Skip to content

Bug: Is there a way to supply overrides for non-specified environment variables when using with terraform  #5822

Open
@toddtarsi

Description

@toddtarsi

Description:

We use the module pattern in terraform, which leads to most resources having a sort of wrapper. As a result, our environment variables are a bit abstracted like this:

resource "aws_lambda_function" "this" {
  ...
  environment {
    variables = var.environment.variables
  }
  ...
}

The command sam build expectedly won't pick up these variables, so they don't get into the generated template.json file, and I think thats fine. The next problem is that sam local invoke xyz won't allow me to inject these dynamic environment variables into the runtime. At least, --env-vars doesn't seem to be able to actually inject environment variables. Is there something I'm missing?

Steps to reproduce:

  1. Have a lambda within a module with environment variables supplied as a map(string) type variable to the module.
  2. sam build; sam local invoke xyz --env-vars env.json
  3. The environment variables needed won't work here.

Observed result:

None of the env vars under Parameters are injected.

Expected result:

I would expect the env-vars under Parameters to be injected as environment variables.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

{
  "version": "1.95.0",
  "system": {
    "python": "3.8.13",
    "os": "macOS-13.4.1-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.2",
    "aws_cdk": "Not available",
    "terraform": "1.4.6"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions