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.76k stars 9.12k forks source link

[Enhancement]: Add container overrides to ecs_task target in aws_scheduler_schedule #34057

Open alexzum opened 11 months ago

alexzum commented 11 months ago

Description

Please enhance the ecs_parameters to allow a resource to pass overrides. See the overrides input parameter in the ECS RunTask API documentation.

aws_scheduler_schedule supports running ecs tasks on a scheduler controlled by eventbridge scheduler.

The workaround for this omission is to switch over to the eventbridge scheduler schedule universal target which is freeform. A caller can provide overrides with it. The universal target is more complicated and the aws terraform provider supports the ecs_task already. It's just missing one field, overrides.

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

Potential Terraform Configuration

# nothing specific

References

  1. ECS RunTask
  2. aws_scheduler_schedule

Would you like to implement a fix?

None

github-actions[bot] commented 11 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

adamantike commented 7 months ago

I found this issue while trying to add ECS container overrides to a new schedule. However, I found that setting the target.input variable was enough for the overrides to be populated:

resource "aws_scheduler_schedule" "this" {
  target {
    ecs_parameters {
      # ...
    }

    input = jsonencode({
      containerOverrides = [
        {
          name    = "app"
          command = ["..."]
        }
      ]
    })
  }
}
rocker1058 commented 3 months ago

@adamantike Hello ,

That is to say that instead of ecs_parameters we can use only the input? because I have tried to use ecs_parameters and I am getting this error:

Error: updating Amazon EventBridge Scheduler Schedule (default/-scale-in-core-scheduler): operation error Scheduler: UpdateSchedule, https response error StatusCode: 400, RequestID: b6ef4cea-d9af-4f7a- b460-409690a605f3, ValidationException: Parameters EcsParameters not supported for the target.

adamantike commented 3 months ago

@rocker1058, this is a more detailed example, in case that helps you. I use both ecs_parameters and input, not one instead of the other.

resource "aws_scheduler_schedule" "this" {
  name                = "test"
  state               = "ENABLED"
  schedule_expression = "cron(0 0 * * ? *)"

  flexible_time_window {
    mode = "OFF"
  }

  target {
    arn = "arn:..."  # ECS cluster ARN

    # role_arn is the ARN for a role with permissions specified here:
    # https://docs.aws.amazon.com/scheduler/latest/UserGuide/setting-up.html#setting-up-execution-role
    role_arn = "arn:..."  

    input = jsonencode({
      containerOverrides = [
        { name = "...", command = ["..."] }
      ]
    })

    ecs_parameters {
      task_definition_arn = "arn:..."  # ARN of the ECS Task Definition to trigger
      launch_type         = "FARGATE"

      network_configuration {
        subnets         = ["..."]
        security_groups = ["..."]
      }
    }

    retry_policy {
      maximum_retry_attempts = 3
    }
  }
}