Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform: ECS service - InvalidParameterException

I am trying to provision an ECS cluster with terraform, everything seems to work well up until I am creating the ecs service:

resource "aws_ecs_service" "ecs-service" {
  name            = "ecs-service"
  iam_role        = "${aws_iam_role.ecs-service-role.name}"
  cluster         = "${aws_ecs_cluster.ecs-cluster.id}"
  task_definition = "${aws_ecs_task_definition.my_cluster.family}"
  desired_count   = 1

  load_balancer {
    target_group_arn  = "${aws_alb_target_group.ecs-target-group.arn}"
    container_port    = 80
    container_name    = "my_cluster"
  }
}

and the IAM role is:

resource "aws_iam_role" "ecs-service-role" {
  name = "ecs-service-role"

  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "ecs-service-role-attachment" {
    role       = "${aws_iam_role.ecs-service-role.name}"
    policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
}

I am getting the following error message:

  • aws_ecs_service.ecs-service: 1 error(s) occurred:

  • aws_ecs_service.ecs-service: InvalidParameterException: Unable to assume role and validate the specified targetGroupArn. Please verify that the ECS service role being passed has the proper permissions.

like image 386
Marc Avatar asked Oct 23 '25 15:10

Marc


1 Answers

In assume_role_policy, can you change the "Principal" line to as mentioned below: You are having ec2.amazonaws.com.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ecs.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
like image 117
krishna_mee2004 Avatar answered Oct 26 '25 10:10

krishna_mee2004



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!