Skip to content

Commit

Permalink
initial fork commit of removing nested cloudwatch log group
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Sep 3, 2024
1 parent 639269f commit cdcad45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ will log to Cloudwatch Logs.
Creates the following resources:

* Lambda function
* IAM role with policy to allow logging to Cloudwatch Logs
* Cloudwatch Logs group
* IAM role with policy to allow logging to Cloudwatch Logs - with the anticipation that these logs are declared as an individual resource

## Usage

Expand Down Expand Up @@ -35,6 +34,11 @@ module "my_lambda_function" {
}
}
# Remember to define the CloudWatch log group separately
resource "aws_cloudwatch_log_group" "my_lambda_logs" {
...
}
```

<!-- BEGIN_TF_DOCS -->
Expand Down
19 changes: 3 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,9 @@ resource "aws_iam_role_policy_attachment" "user_policy_attach" {
policy_arn = var.role_policy_arns[count.index]
}

# Cloudwatch Logs
resource "aws_cloudwatch_log_group" "main" {
name = "/aws/lambda/${local.full_name}"
retention_in_days = var.cloudwatch_logs_retention_days
# set the key, else empty string
kms_key_id = var.cloudwatch_encryption_key_arn
tags = {
Name = local.full_name
}
}

# Lambda function from s3
resource "aws_lambda_function" "main_from_s3" {
count = local.from_github ? 0 : 1
depends_on = [aws_cloudwatch_log_group.main]
count = local.from_github ? 0 : 1

s3_bucket = var.s3_bucket
s3_key = var.s3_key
Expand Down Expand Up @@ -138,9 +126,8 @@ resource "null_resource" "get_github_release_artifact" {

# Only on Lambda function from github
resource "aws_lambda_function" "main_from_gh" {
count = local.from_github ? 1 : 0
depends_on = [aws_cloudwatch_log_group.main,
null_resource.get_github_release_artifact]
count = local.from_github ? 1 : 0
depends_on = [null_resource.get_github_release_artifact]

filename = var.github_filename
source_code_hash = var.validation_sha
Expand Down

0 comments on commit cdcad45

Please sign in to comment.