terraform-aws-modules/terraform-aws-ecs

Log driver awslogs requires options

Closed this issue · 3 comments

Description

I have set cloudwatch_log_group_name. However, I am getting "Error: creating ECS Task Definition (ddagent-p): ClientException: Log driver awslogs requires options: awslogs-group". The example does not set awslogs-group.

⚠️ 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

  • Module version [Required]: 5.9.1

  • Terraform version: 1.7.3

  • Provider version(s): aws v5.37.0

Reproduction Code [Required]

Steps to reproduce the behavior:

My terraform configuration file is pretty similar to the EC2 example:

      enable_cloudwatch_logging              = true
      create_cloudwatch_log_group            = true
      cloudwatch_log_group_name              = "/aws/ecs/X-p"
      cloudwatch_log_group_retention_in_days = 7
      log_configuration = {
        logDriver = "awslogs"
        options = {
          awslogs-region        = "X-X-2"
        }
      }

Expected behavior

ECS service is created with related cloudwatch log group.

Actual behavior

Error: creating ECS Task Definition (X-p): ClientException: Log driver awslogs requires options: awslogs-group

Terminal Output Screenshot(s)

Additional context

@monelgordillo @bryantbiggs yes, the current example is not fully correct because Terraform doesn't support deep map merge. My apologies that I didn't pay attention to Terraform's shallow merge behavior while making it 😕.

I've prepared a fix for the EC2 example - #170

Based on that, to define a custom log_configuration, it's required to define all params at the log_configuration.options map or use defaults defined at the appropriate local.

log_configuration = merge(
{ for k, v in {
logDriver = "awslogs",
options = {
awslogs-region = data.aws_region.current.name,
awslogs-group = try(aws_cloudwatch_log_group.this[0].name, ""),
awslogs-stream-prefix = "ecs"
},
} : k => v if var.enable_cloudwatch_logging },
var.log_configuration
)

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.