3

We are using terraform to launch ECS containers in AWS infra using custom task definition. As we didn't require full infra to be launched every-time, a part only for launching ECS container was segregated.

The launch was happening correctly, till ECS launch code was segregated, then the ECS service launch started giving an error indicating Idempotent issue.

│ Error: error creating target service: error waiting for ECS service (sandbox) creation: InvalidParameterException: Creation of service was not idempotent. 
│  
│   with aws_ecs_service.ecs_service_target, 
│   on aws_infra_ecs.tf line 100, in resource "aws_ecs_target" "ecs_service_target": 
│  100: resource "aws_ecs_target" "ecs_service_target" { 
│

ECS service is defined somewhat like below:

resource "aws_ecs_service" "ecs_service_target" {
    desired_count = 1
    name   = "target"
    launch_type = "FARGATE"
    cluster = data.aws_ecs_cluster.cluster_target.id
    enable_ecs_managed_tasks = true
    task_definition = aws_ecs_task_definition.target_taskdef.arn
    platform_version = "1.4.0"
...
    load_balancer {
         ...
         target_group_arn = data.aws_lb_target_group.aws_target.arn
    }
...
    network_configuration {
    ...
       security_groups = [ data.aws_security_group.target_sg.id ]
       subnets = [ "subet-5767c3c2" ] # A dynamic subnet reference id is used here 
    }
    depends_upon = [
       var.second_service_name,
       aws_ecs_task_definition.target_taskdef,
       data.aws_efs_access_point.target_ap
    ]
...
}

I was expecting the problems to be one of following kind:

  1. Subnet selected may be different due to variable based selection
  2. Use of indirect data references (rather than direct resource reference) may cause issue
  3. task definition JSON encoding issue

What might be other causes for such a problem.

khelender
  • 61
  • 6
  • 1
    Found the problem be to a conflict in name space of ECS service. Two different terraform deployments were targeting the same name. – khelender Jul 01 '21 at 14:43

0 Answers0