Skip to content

terraform redeploys lambda and lambda_layer even when no change to code #38

@socraticDevBlog

Description

@socraticDevBlog

Terraform tracks changes in your infrastructure based on the resources you define in your configuration files. Even if you only modify the README file in your repository, if you are using Terraform's remote state management and have version control configured to trigger Terraform runs on any changes, it will reapply the entire configuration.

Here are some possible reasons why Terraform might be updating the aws_lambda_layer_version and aws_lambda_function resources:

  1. Dependencies: The Lambda function might depend on the changes you made, even if it's not directly related to the README file. If any resource the Lambda function relies on changes, Terraform will update it as well.

  2. Source Code Hashes: Terraform uses source code hashes to determine if the Lambda function's source code has changed. Even if you only changed the README, if the source code hash changes (for instance, due to the zip file including timestamps or metadata), Terraform will consider it a change and update the Lambda function.

  3. Remote State Changes: If your Terraform state is stored remotely (e.g., in an S3 bucket), and your pipeline triggers a Terraform run on any change in the repository, Terraform will compare the remote state with the current configuration, detecting changes and updating resources as necessary.

To minimize unintended updates, you can:

  • Refine your triggering mechanism in the pipeline to only execute Terraform when necessary, perhaps by excluding changes to certain files.
  • Review your dependencies to ensure they are properly defined. If a resource depends on external factors that shouldn't affect its configuration, consider isolating or decoupling those dependencies.
  • Double-check your Terraform state management strategy to ensure it aligns with your workflow and requirements.

By carefully managing your Terraform workflow and understanding its behavior, you can reduce the likelihood of unexpected updates.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions