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.76k stars 9.11k forks source link

Failed to update scaling policy: ValidationException: Target group #16888

Open Zogoo opened 3 years ago

Zogoo commented 3 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Terraform 12.0.6

Affected Resource(s)

aws_ecs_service

Terraform Configuration Files

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

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

Debug Output

  # module.ecs_cluster.aws_ecs_service.portal must be replaced
+/- resource "aws_ecs_service" "web" {
        cluster                            = "arn:aws:ecs:ap-northeast-1:****:cluster/name_of_cluster"
        deployment_maximum_percent         = 150
        deployment_minimum_healthy_percent = 50
      ~ desired_count                      = 2 -> 3
        enable_ecs_managed_tags            = false
        health_check_grace_period_seconds  = 60
      ~ iam_role                           = "aws-service-role" -> (known after apply)
      ~ id                                 = "arn:aws:ecs:ap-northeast-1:****:service/name_of_cluster/name_of_service" -> (known after apply)
      + launch_type                        = (known after apply)
        name                               = "name_of_service"
      + platform_version                   = (known after apply)
      - propagate_tags                     = "NONE" -> null
        scheduling_strategy                = "REPLICA"
      - tags                               = {} -> null
      ~ task_definition                    = "name_of_task:28" -> (known after apply)
        wait_for_steady_state              = false
      - capacity_provider_strategy {
          - base              = 0 -> null
          - capacity_provider = "name_of_auto_scaling_group" -> null
          - weight            = 1 -> null
        }
      - deployment_controller {
          - type = "ECS" -> null
        }
      + load_balancer { # forces replacement
          + container_name   = "name_of_container"
          + container_port   = 8080
          + target_group_arn = "arn:aws:elasticloadbalancing:ap-northeast-1:****:targetgroup/name_of_target_group/****"
        }
      - load_balancer { # forces replacement
          - container_name   = "name_of_container" -> null
          - container_port   = 8080 -> null
          - target_group_arn = "arn:aws:elasticloadbalancing:ap-northeast-1:***:targetgroup/name_of_target_group/****" -> null
        }
        ordered_placement_strategy {
            field = "attribute:ecs.availability-zone"
            type  = "spread"
        }
        ordered_placement_strategy {
            field = "instanceId"
            type  = "spread"
        }
        placement_constraints {
            type = "distinctInstance"
        }
    }

Panic Output

Error: InvalidParameterException: Creation of service was not idempotent. "name_of_ecs_service"

Error: Failed to update scaling policy: ValidationException: Target group target_group_name is not attached to resource name_of_ecs_service

Expected Behavior

Terraform should update ecs service object in aws with terraform apply

Actual Behavior

Terraform trying to create new ecs service before delete but still failing terraform apply

Steps to Reproduce

  1. terraform apply
tyrannosaurus-becks commented 1 year ago

This issue persists in version 4.2.0 of the AWS provider.