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.82k stars 9.17k forks source link

Unable to Create DAEMON Service In ECS Cluster with default_capacity_provider_strategy #16772

Open pilchkinstein-perspectum opened 3 years ago

pilchkinstein-perspectum commented 3 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Terraform v0.13.5

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "aws_ecs_service" "service" {
  name            = "service_16772"
  task_definition = aws_ecs_task_definition.task.family
  cluster         = "cluster_16772"

  scheduling_strategy = "DAEMON"

  placement_constraints {
    type = "distinctInstance"
  }
}

resource "aws_ecs_task_definition" "task" {
  container_definitions    = file("service.json")
  family                   = "task_16772"
  requires_compatibilities = ["EC2"]
}

resource "aws_ecs_cluster" "cluster" {
  name               = "cluster_16772"
  capacity_providers = ["cps_16772"]
  default_capacity_provider_strategy {
    capacity_provider = "cps_16772"
    weight            = "100"
    base              = "1"
  }
}

resource "aws_ecs_capacity_provider" "ecs_capacity_provider" {
  name = "cps_16772"
  auto_scaling_group_provider {
    auto_scaling_group_arn = aws_autoscaling_group.asg.arn
  }
}

resource "aws_autoscaling_group" "asg" {
  name             = "asg_16772"
  max_size         = 1
  min_size         = 1
  desired_capacity = 1

  launch_template {
    id      = aws_launch_template.lc.id
    version = aws_launch_template.lc.latest_version
  }

  availability_zones = ["us-east-1a"]
}

resource "aws_launch_template" "lc" {
  image_id = "ami-00ddb0e5626798373"
  instance_type = "t2.small"
}

// service.json

[
  {
    "name": "main",
    "image": "nginx",
    "cpu": 10,
    "memory": 512,
    "essential": true,
    "portMappings": [
      {
        "containerPort": 80,
        "hostPort": 80
      }
    ]
  }
]

Debug Output

bug-16772-debug.log

Panic Output

N/A

Expected Behavior

New DAEMON service should be created on each instance in the ECS cluster

Actual Behavior

No service is created. Terraform returns the following:-

Error: InvalidParameterException: Specifying a capacity provider strategy is not supported when you create a service using the DAEMON scheduling strategy. "cadvisor"

Steps to Reproduce

  1. terraform apply -target=aws_launch_template.lc -target=aws_autoscaling_group.asg -target=aws_ecs_capacity_provider.ecs_capacity_provider
  2. terraform apply -target=aws_ecs_cluster.cluster -target=aws_ecs_task_definition.task
  3. terraform apply -target=aws_ecs_service.service

Important Factoids

None

References

pilchkinstein-perspectum commented 3 years ago

This is now reproducible behaviour. An ECS cluster with a default capacity provider cannot create a DAEMON task. The workaround is:-

  1. update the ECS cluster and remove the default capacity provider
  2. create the DAEMON task
  3. update the ECS cluster and add back the default capacity provider
wendtek commented 3 years ago

I was able to get around this by setting launch_type = "EC2" on the service. I got this tip from https://github.com/aws/containers-roadmap/issues/692 The strange thing is the AWS provider docs indicate EC2 is the default value for that argument, but it did not work until I explicitly set it on the service.

Edit: I see now, while my method successfully applied, the service was not deployed to the nodes in the default capacity provider. I had to change from using launch_type to manually specifying the capacity_provider_strategy, which results in the original error again.

pilchkinstein-perspectum commented 3 years ago

Any news on this? I'd hate to see it suddenly be archived due to inaction

infracaninophile commented 3 years ago

Contrary to @wendtek 's experience, I tried the launch_type = "EC2" explicit setting, and it worked fine for me: DAEMON processes successfully running on every instance in the cluster, whether using the default capacity provider or not.

terraform 0.15.3 aws-provider 3.45.0

dspv commented 2 years ago

Contrary to @wendtek 's experience, I tried the launch_type = "EC2" explicit setting, and it worked fine for me: DAEMON processes successfully running on every instance in the cluster, whether using the default capacity provider or not.

terraform 0.15.3 aws-provider 3.45.0

Worked for me, thanks

eyal-solomon1 commented 2 years ago

Contrary to @wendtek 's experience, I tried the launch_type = "EC2" explicit setting, and it worked fine for me: DAEMON processes successfully running on every instance in the cluster, whether using the default capacity provider or not.

terraform 0.15.3 aws-provider 3.45.0

worked for me too, thanks @infracaninophile

github-actions[bot] commented 1 week ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!