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

[Bug]: aws_lambda_function with empty environment variables map flaps #29255

Closed
oeuftete opened this issue Feb 6, 2023 · 3 comments · Fixed by #29839
Closed

[Bug]: aws_lambda_function with empty environment variables map flaps #29255

oeuftete opened this issue Feb 6, 2023 · 3 comments · Fixed by #29839
Labels
bug Addresses a defect in current functionality. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/lambda Issues and PRs that pertain to the lambda service.
Milestone

Comments

@oeuftete
Copy link

oeuftete commented Feb 6, 2023

Terraform Core Version

1.3.7

AWS Provider Version

4.53.0

Affected Resource(s)

  • aws_lambda_function

Expected Behavior

When setting the following block in aws_lambda_function, the resource should not repeatedly want to apply a change:

  environment {
    variables = {}
  }

Actual Behavior

Planning after an apply showed the environment block being added again.

Relevant Error/Panic Output Snippet

$ terraform apply "tfplan"
aws_iam_role.function: Creating...
aws_iam_role.function: Creation complete after 1s [id=environment-bug-repro-test]
aws_lambda_function.function: Creating...
aws_lambda_function.function: Still creating... [10s elapsed]
aws_lambda_function.function: Still creating... [20s elapsed]
aws_lambda_function.function: Creation complete after 22s [id=environment-bug-repro-test]

$ terraform plan
aws_iam_role.function: Refreshing state... [id=environment-bug-repro-test]
aws_lambda_function.function: Refreshing state... [id=environment-bug-repro-test]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_lambda_function.function will be updated in-place
  ~ resource "aws_lambda_function" "function" {
        id                             = "environment-bug-repro-test"
        tags                           = {}
        # (21 unchanged attributes hidden)

      + environment {}

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Terraform Configuration Files

locals {
  test_name = "environment-bug-repro-test"
}

resource "aws_lambda_function" "function" {
  filename         = "lambda.zip"
  function_name    = local.test_name
  role             = aws_iam_role.function.arn
  handler          = "lambda_function.lambda_handler"
  runtime          = "ruby2.7"
  source_code_hash = filebase64sha256("lambda.zip")

  environment {
    variables = {}
  }
}

resource "aws_iam_role" "function" {
  name = local.test_name

  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF
}

Steps to Reproduce

terraform plan -out tfplan
terraform apply tfplan
terraform plan

Debug Output

No response

Panic Output

No response

Important Factoids

Workarounds

If you're just specifying it statically, don't add the environment block. If it's a scenario where you are passing the environment variables as a (possibly empty) map, this worked for me:

  dynamic "environment" {
    for_each = length(var.env_vars) == 0 ? [] : ["dummy"]

    content {
      variables = var.env_vars
    }
  }

References

Looks similar to #28495.

Would you like to implement a fix?

None

@oeuftete oeuftete added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Feb 6, 2023
@github-actions
Copy link

github-actions bot commented Feb 6, 2023

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/iam Issues and PRs that pertain to the iam service. service/lambda Issues and PRs that pertain to the lambda service. labels Feb 6, 2023
@jar-b jar-b added good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. and removed needs-triage Waiting for first response or review from a maintainer. service/iam Issues and PRs that pertain to the iam service. labels Feb 6, 2023
@github-actions github-actions bot added this to the v4.59.0 milestone Mar 10, 2023
@github-actions
Copy link

This functionality has been released in v4.59.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants