5

I have the following config for ECS using terraform and apex.

resource "aws_ecs_task_definition" "task" {
    ...
      container_definitions = <<DEFINITION
      [
       {
    "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "${aws_cloudwatch_log_group.test_log_group.arn}",
          "awslogs-region": "${var.region}",
          "awslogs-stream-prefix": "/ecs"
        }
      }
    }
   ]
  DEFINITION
  }

And the cloudwatch resource configuration:

resource "aws_cloudwatch_log_group" "test_log_group" {
  name              = "test_log_group"
  retention_in_days = 30
}

When running apex infra apply, I get the following error! Tried with different character sets, with and without special characters, etc. Nothing worked. Hope some one can help me out:

ClientException: Log driver awslogs option 'awslogs-group' contains invalid characters.
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
shwz
  • 426
  • 1
  • 6
  • 22

1 Answers1

7

The awslogs Docker driver takes the group name for the value of awslogs-group, not the ARN of the log group.

So you just want to use the following:

resource "aws_ecs_task_definition" "task" {
  # ...
  container_definitions = <<DEFINITION
[
  {
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
          "awslogs-group": "${aws_cloudwatch_log_group.test_log_group.name}",
          "awslogs-region": "${var.region}",
          "awslogs-stream-prefix": "/ecs"
      }
    }
  }
]
DEFINITION
}
ydaetskcoR
  • 53,225
  • 8
  • 158
  • 177