Skip to content

Conversation

@bendrucker
Copy link
Contributor

@bendrucker bendrucker commented Jul 14, 2023

What does this PR do?

Makes explicit the implicit dependency between the Lambda and the CloudWatch log group with name = format("/aws/lambda/%s", var.name).

Motivation

This pattern of hardcoding the Lambda CWL naming scheme with depends_on is used to have Terraform manage a CloudWatch Logs log group for a Lambda. Lambdas don't take a log group, but if one already exists with the right name they'll just use it.

Without depends_on, there is a (very unlikely) race condition. If the Lambda managed to be created and get invoked before Terraform created the log group, Terraform will hit a conflict that only import can resolve.

This also ensures that during a terraform destroy that the graph is cleaned up in the reverse direction and the Lambda is destroyed before the log group. This is potentially important, because the Lambda will re-create the log group when invoked.

Testing

terraform validate is the most testing we can do here.

@bendrucker bendrucker merged commit 07a9083 into main Jul 17, 2023
@bendrucker bendrucker deleted the lambda-depends-on-cwl branch July 17, 2023 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants