fix: declare Lambda's dependency on log group #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_onis 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 onlyimportcan resolve.This also ensures that during a
terraform destroythat 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 validateis the most testing we can do here.