terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
885 stars 658 forks source link

CloudWatch group not destroying #563

Closed dspv closed 1 month ago

dspv commented 2 months ago

Description

When destroy Lambda - CloudWatch log group is not destroyed

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

Your version of Terraform is out of date! The latest version is 1.8.2. You can update by downloading from https://www.terraform.io/downloads.html


## Reproduction Code [Required]

module mezmo_lambda { source = "terraform-aws-modules/lambda/aws" version = "~> 7.0"

function_name = "usw2-dev-ptest-1mezmo-lambda" description = "Push logs CloudWatch -> Mezmo for usw2-dev-ptest1" handler = "index.handler" runtime = "nodejs20.x" timeout = 10 memory_size = 256 maximum_retry_attempts = 0 create_package = false local_existing_package = "${path.module}/lambda-logdna-cloudwatch-to-s3.zip" tags = var.standard_tags cloudwatch_logs_retention_in_days = 3

environment_variables = { LOGDNA_KEY = LOGDNA_TAGS = "usw2-dev-ptest" LOG_RAW_EVENT = "yes" } }


Steps to reproduce the behavior:

<!-- Are you using workspaces? -->
NO
<!-- Have you cleared the local cache (see Notice section above)? -->
YES
<!-- List steps in order that led up to the issue you encountered -->
Just run terraform apply

## Expected behavior
When applying once again I want to see everything is applied correctly

## Actual behavior

β”‚ Error: creating CloudWatch Logs Log Group (/aws/lambda/usw2-dev-ptest1-mezmo-lambda): operation error CloudWatch Logs: CreateLogGroup, https response error StatusCode: 400, RequestID: 99b8bbdf-cb2b-4a80-967b-7a141a40d70d, ResourceAlreadyExistsException: The specified log group already exists β”‚ β”‚ with module.environment.module.mezmo_lambda.aws_cloudwatch_log_group.lambda[0], β”‚ on .terraform/modules/environment.mezmo_lambda/main.tf line 218, in resource "aws_cloudwatch_log_group" "lambda": β”‚ 218: resource "aws_cloudwatch_log_group" "lambda" { β”‚ β•΅

antonbabenko commented 2 months ago

If the Log Group is not empty, it won't be deleted, and you need to specify use_existing_cloudwatch_log_group = true.

It would be great if there is a way to configure skip_destroy argument to be able to manage the lifecycle of log groups as well. Pull-request is welcome!

antonbabenko commented 1 month ago

This issue has been resolved in version 7.4.0 :tada:

github-actions[bot] commented 4 weeks ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.