Skip to content

fix: prevent Lambda log group creation race during deployment #5323

Description

@edersonbrilhante

Description

Terraform can hit a race condition while deploying the runner Lambdas and their CloudWatch log groups.

For example, in modules/runners/scale-down.tf, Terraform may create the scale-down Lambda and its scheduled EventBridge invocation before it creates the explicitly managed CloudWatch log group. If the schedule invokes the Lambda during that window, AWS automatically creates /aws/lambda/<function-name>. Terraform then attempts to create the same log group and fails because it already exists.

Expected behavior

Every Terraform-managed Lambda log group must exist before its Lambda can be created or invoked, preventing AWS from creating the log group outside Terraform. All Lambda modules should use the same dependency pattern for consistent behavior and maintainability.

Scope

  • Standardize all Terraform-managed Lambda log groups in the repository, including these CloudWatch log-group/Lambda pairs:
    • aws_cloudwatch_log_group.ami_housekeeper in modules/ami-housekeeper/main.tf
    • aws_cloudwatch_log_group.syncer in modules/runner-binaries-syncer/runner-binaries-syncer.tf
    • aws_cloudwatch_log_group.scale_down
    • aws_cloudwatch_log_group.scale_up
    • aws_cloudwatch_log_group.ssm_housekeeper
    • aws_cloudwatch_log_group.main
    • aws_cloudwatch_log_group.pool
    • aws_cloudwatch_log_group.webhook in modules/webhook/direct
    • aws_cloudwatch_log_group.dispatcher in modules/webhook/eventbridge
    • aws_cloudwatch_log_group.webhook in modules/webhook/eventbridge
  • Derive each log-group name without referencing the Lambda resource, avoiding the current implicit log group -> Lambda dependency.
  • Make each Lambda explicitly depend on its own log group.
  • Preserve the existing function and log-group names, retention settings, encryption, and tags.
  • Add or update tests to verify the dependency ordering for all affected Lambdas.

Acceptance criteria

  • A fresh deployment cannot invoke a managed Lambda before Terraform has created its CloudWatch log group.
  • Terraform no longer fails with a duplicate/already-existing log-group error when a Lambda is invoked during deployment.
  • All Terraform-managed Lambda/log-group pairs follow the same dependency pattern.

Activity

  1. added a commit that references this issue on Sep 2, 2026
    2f844ab
  2. added a commit that references this issue on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions