hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.73k stars 9.09k forks source link

[Enhancement]: Add Retention Key to Logging Configuration in `aws_mwaa_environment` #37910

Open jacobcbeaudin opened 3 months ago

jacobcbeaudin commented 3 months ago

Description

The current logging configuration for MWAA (aws_mwaa_environment) does not allow setting the retention period for logs. The default retention period is fixed at 3 months. To provide more flexibility and control over log management, it would be beneficial to include an optional retention key in the logging configuration. This key should allow users to specify their desired log retention period in days.

Proposed Solution

Add an optional retention parameter to each logging configuration block within the aws_mwaa_environment resource. This parameter should accept an integer representing the number of days to retain the logs.

Benefits

Impact

This change is backward-compatible as it introduces an optional parameter. Existing configurations without the retention key will continue to use the default 3-month retention period.

Additional Context

Include any references to AWS documentation or community discussions that support the need for this feature.

Affected Resource(s) and/or Data Source(s)

Potential Terraform Configuration

resource "aws_mwaa_environment" "example" {
  name               = "example"
  execution_role_arn = aws_iam_role.example.arn
  source_bucket_arn  = aws_s3_bucket.example.arn
  dag_s3_path        = "dags/"

  network_configuration {
    security_group_ids = [aws_security_group.example.id]
    subnet_ids         = aws_subnet.private[*].id
  }

  logging_configuration {
    dag_processing_logs {
      enabled   = true
      log_level = "DEBUG"
      retention = 30  # Retain logs for 30 days
    }

    scheduler_logs {
      enabled   = true
      log_level = "INFO"
      retention = 90  # Retain logs for 90 days
    }

    task_logs {
      enabled   = true
      log_level = "WARNING"
      retention = 60  # Retain logs for 60 days
    }

    webserver_logs {
      enabled   = true
      log_level = "ERROR"
      retention = 30  # Retain logs for 30 days
    }

    worker_logs {
      enabled   = true
      log_level = "CRITICAL"
      retention = 15  # Retain logs for 15 days
    }
  }
}

References

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mwaa_environment

Would you like to implement a fix?

None

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

acwwat commented 2 months ago

It doesn't look like the API supports setting log retention period. The API technically can provide the log group ARNs on read (but not supported by aws_mwaa_environment yet), but there's no way to easily turn that into a aws_cloudwatch_log_group resource where the log retention is set.

Your best bet is to open an AWS support case to request for the CreateEnvironment and UpdateEvnironment APIs to support bring your own CloudWatch log groups. This will then enable creation of aws_cloudwatch_log_group resources with custom log retention periods and provide them to the aws_mwaa_environment resource.