Skip to content

Creation of ECS service failed with enabled service discovery #175

Open
@Wishpering

Description

@Wishpering

Describe the Bug

Can't deploy ECS service with enabled service discovery

Expected Behavior

ECS service with enabled service discovery

Steps to Reproduce

Module are used in this way (ECS + ALB + EFS + Service Discovery)

module "service" {
  source = "git::https://github.com/cloudposse/terraform-aws-ecs-alb-service-task.git?ref=0.64.1"

  name                      = var.name
  environment               = var.environment
  container_definition_json = local.containers
  desired_count             = var.desired_count
  ecs_cluster_arn           = var.ecs_cluster_arn
  efs_volumes               = local.jenkins_volume
  ecs_load_balancers = [
    {
      container_name   = var.name
      container_port   = var.container_port
      elb_name         = ""
      target_group_arn = aws_lb_target_group.this.arn
    }
  ]
  launch_type                    = "EC2"
  network_mode                   = "bridge"
  subnet_ids                     = var.subnet_ids
  tags                           = var.common_tags
  task_cpu                       = null
  task_memory                    = null
  vpc_id                         = var.vpc_id
  ignore_changes_task_definition = false
  use_old_arn                    = false
  propagate_tags                 = "TASK_DEFINITION"
  service_registries              = [{
      registry_arn = aws_service_discovery_service.this.arn
      port         = 8080
      container_name = var.name
      container_port = 8080
    }]
}

Now ECS service won't deploy cause of this error:

module.service.aws_ecs_service.default[0]: Creating...
Error: failed creating ECS service (jenkins): InvalidParameterException: You cannot specify an IAM role for services that require a service linked role.
  on .terraform/modules/service/[main.tf](http://main.tf/) line 631, in resource "aws_ecs_service" "default":
 631: resource "aws_ecs_service" "default" {
Releasing state lock. This may take a few moments...
[terragrunt] 2022/09/30 10:54:48 Hit multiple errors:
exit status 1

When I am deleting service_registries, everything works fine.
Also switching network_mode to AWSVPC solves this problem too (due to lack of need for IAM policy in this case)

Environment:

  • Terraform = 0.14.11
  • Terragrunt = 0.25.3
  • AWS Provider = 3.75.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions