CodexBloom - Programming Q&A Platform

Terraform scenarios to apply changes to AWS Lambda function permissions after module refactor

👀 Views: 76 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-05
terraform aws-lambda module hcl

I've encountered a strange issue with I'm building a feature where After trying multiple solutions online, I still can't figure this out... I'm working with an scenario where Terraform does not apply changes to the permissions of an AWS Lambda function after I refactored my code to use modules. Initially, the permissions were set directly in the Lambda resource definition, but now that I've moved this logic into a separate module, the permissions seem to be ignored during `terraform apply`. I'm using Terraform version 1.3.7 and the AWS provider version 4.0.0. Here's a simplified version of my module code: ```hcl module "lambda_function" { source = "./modules/lambda" function_name = "my_lambda" handler = "index.handler" role = aws_iam_role.lambda_exec.arn source_code_hash = filebase64sha256("./lambda.zip") } ``` And within the module, I have the following configuration to set up the Lambda permissions: ```hcl resource "aws_lambda_permission" "allow_api" { statement_id = "AllowExecutionFromAPI" action = "lambda:InvokeFunction" function = var.function_name principal = "apigateway.amazonaws.com" source_arn = aws_api_gateway_deployment.api.execution_arn } ``` After running `terraform apply`, I expect to see the new permissions getting applied. However, Terraform outputs: ``` behavior: No changes. Your infrastructure matches the configuration. ``` I've checked that the Lambda function and API Gateway resources are properly defined and deployed. I've also ensured that the `function_name` variable is being passed correctly to the module. I tried running `terraform refresh` to see if it would help but still no changes were detected. Should I be using a different method to manage permissions for the Lambda function within a module? Any insights on what I might be missing here would be greatly appreciated! I'm working on a API that needs to handle this. Thanks in advance! I've been using Hcl for about a year now. I'm open to any suggestions. I've been using Hcl for about a year now. Thanks, I really appreciate it! What's the correct way to implement this?