2

In my terraform code, I am trying to attach an auto-scaling group to my ECS Service using aws_autoscaling_target.

resource "aws_appautoscaling_target" "service_app_asg_target" {
  resource_id = "${aws_ecs_service.service_app.arn}"
  min_capacity = 2
  max_capacity = 6
  role_arn = "${aws_iam_role.ecs_autoscale_role.arn}"
}

When I apply this, amazon gives me the error

Unsupported service namespace, resource type or scalable dimension

What's wrong with my attachment?

philippe
  • 223
  • 2
  • 9

2 Answers2

5

You didn't correctly format the resource_id in your aws_appautoscaling_target. It needs to be in the format service/clusterName/serviceName, and terraform will not format it for you. Try:

resource_id = "service/${aws_ecs_cluster.MY_CLUSTER.name}/${aws_ecs_service.MY_SERVICE.name}"
philippe
  • 223
  • 2
  • 9
1

Here is the CloudFormation version in case someone needs it. Node the cluster and the service are text not references

   ScalableTarget:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      RoleARN: !GetAtt AutoScalingRole.Arn
      ResourceId: service/ECSCluster/ECSService