Skip to content

Can't change desired count for a task that didn't change within the last 3 months #43445

@xalvarez

Description

@xalvarez

Terraform and AWS Provider Version

Terraform v1.12.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v6.4.0

Affected Resource(s) or Data Source(s)

  • aws_ecs_service

Expected Behavior

When changing the desired count of an ECS service, apply should work even if the corresponding ECS task is old.

Actual Behavior

Since AWS provider version 6.4.0, ListServiceDeployments is used to get the latest deployment without time filters. If no filter is provided, by default the API looks for a deployment from the last 3 months. If none is found, terraform apply fails.

Relevant Error/Panic Output

Error: waiting for ECS Service (arn:aws:ecs:eu-central-1:xxxxx) update: operation error ECS: ListServiceDeployments, https response error StatusCode: 400, RequestID: xxxxx, InvalidParameterException: Before and After time filter must be within the last 3 months.

Sample Terraform Configuration

Click to expand configuration
resource "aws_ecs_service" "service" {
  name                             = "example-service-dev"
  cluster                          = aws_ecs_cluster.service-cluster.id
  task_definition                  = aws_ecs_task_definition.task.arn
  desired_count                    = 1
  launch_type                      = "FARGATE"
  health_check_grace_period_seconds = 180
  wait_for_steady_state            = true

  network_configuration {
    security_groups  = [data.aws_security_group.alb_security_group.id, aws_security_group.service_security_group.id]
    subnets          = tolist(data.aws_subnets.private.ids)
    assign_public_ip = false
  }

  load_balancer {
    target_group_arn = aws_lb_target_group.target_group.id
    container_name   = "example-container"
    container_port   = 8080
  }

  lifecycle {
    create_before_destroy = true
  }
}

Steps to Reproduce

  1. Change desired count
  2. Run terraform apply

Debug Logging

Click to expand log output
http.request.body=
| {"cluster":"arn:aws:ecs:REGION:ACCOUNT_ID:cluster/SERVICE_NAME","createdAt":{"after":1736836063.319},"service":"SERVICE_NAME"}
net.peer.name=ecs.REGION.amazonaws.com rpc.method=ListServiceDeployments rpc.system=aws-api http.method=POST http.request.header.authorization="[REDACTED]" tf_resource_type=aws_ecs_service http.request.header.amz_sdk_invocation_id=[REDACTED] tf_mux_provider="*schema.GRPCProviderServer" http.request.header.x_amz_security_token="[REDACTED]" http.request_content_length=166 tf_aws.sdk=aws-sdk-go-v2 http.request.header.x_amz_date=[REDACTED] tf_rpc=ApplyResourceChange http.request.header.content_type=application/x-amz-json-1.1 http.user_agent="APN/1.0 HashiCorp/1.0 Terraform/1.12.2 (+https://www.terraform.io) terraform-provider-aws/6.4.0 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go-v2/1.36.5 ua/2.1 os/linux lang/go#1.24.5 md/GOOS#linux md/GOARCH#amd64 api/ecs#1.60.0 m/r,t,u" rpc.service=ECS aws.region=REGION http.request.header.x_amz_target=AmazonEC2ContainerServiceV20141113.ListServiceDeployments http.url=https://ecs.REGION.amazonaws.com/ tf_provider_addr=registry.terraform.io/hashicorp/aws tf_req_id=[REDACTED] timestamp="2025-07-18T14:48:08.635+0200"

2025-07-18T14:48:08.700+0200 [DEBUG] provider.terraform-provider-aws_v6.4.0_x5: HTTP Response Received:
http.response.body=
| {"__type":"InvalidParameterException","message":"Before and After time filter must be within the last 3 months."}
http.response.header.date="Fri, 18 Jul 2025 12:48:08 GMT" rpc.method=ListServiceDeployments tf_aws.sdk=aws-sdk-go-v2 tf_aws.signing_region="" tf_provider_addr=registry.terraform.io/hashicorp/aws http.status_code=400 @caller=github.com/hashicorp/aws-sdk-go-base/[email protected]/logging/tf_logger.go:45 http.duration=64 http.response.header.content_type=application/x-amz-json-1.1 http.response_content_length=113 rpc.system=aws-api tf_req_id=[REDACTED] tf_resource_type=aws_ecs_service @module=aws aws.region=REGION http.response.header.x_amzn_requestid=[REDACTED] rpc.service=ECS tf_mux_provider="*schema.GRPCProviderServer" tf_rpc=ApplyResourceChange timestamp="2025-07-18T14:48:08.700+0200"

2025-07-18T14:48:08.701+0200 [DEBUG] provider.terraform-provider-aws_v6.4.0_x5: request failed with unretryable error https response error StatusCode: 400, RequestID: [REDACTED], InvalidParameterException: Before and After time filter must be within the last 3 months.: @module=aws aws.region=REGION rpc.method=ListServiceDeployments tf_provider_addr=registry.terraform.io/hashicorp/aws tf_resource_type=aws_ecs_service tf_aws.sdk=aws-sdk-go-v2 rpc.system=aws-api @caller=github.com/hashicorp/aws-sdk-go-base/[email protected]/logging/tf_logger.go:45 rpc.service=ECS tf_mux_provider="*schema.GRPCProviderServer" tf_req_id=[REDACTED] tf_rpc=ApplyResourceChange timestamp="2025-07-18T14:48:08.701+0200"

2025-07-18T14:48:08.705+0200 [ERROR] provider.terraform-provider-aws_v6.4.0_x5: Response contains error diagnostic: tf_rpc=ApplyResourceChange @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="waiting for ECS Service (arn:aws:ecs:REGION:ACCOUNT_ID:service/SERVICE_NAME/SERVICE_NAME) update: operation error ECS: ListServiceDeployments, https response error StatusCode: 400, RequestID: [REDACTED], InvalidParameterException: Before and After time filter must be within the last 3 months." tf_proto_version=5.9 tf_provider_addr=registry.terraform.io/hashicorp/aws tf_req_id=[REDACTED] @caller=github.com/hashicorp/[email protected]/tfprotov5/internal/diag/diagnostics.go:58 diagnostic_detail="" tf_resource_type=aws_ecs_service timestamp="2025-07-18T14:48:08.704+0200"

2025-07-18T14:48:08.709+0200 [DEBUG] State storage *remote.State declined to persist a state snapshot

2025-07-18T14:48:08.709+0200 [ERROR] vertex "module.fargate-service.aws_ecs_service.service" error: waiting for ECS Service (arn:aws:ecs:REGION:ACCOUNT_ID:service/SERVICE_NAME/SERVICE_NAME) update: operation error ECS: ListServiceDeployments, https response error StatusCode: 400, RequestID: [REDACTED], InvalidParameterException: Before and After time filter must be within the last 3 months.

GenAI / LLM Assisted Development

n/a

Important Facts and References

No response

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.prioritizedPart of the maintainer teams immediate focus. To be addressed within the current quarter.regressionPertains to a degraded workflow resulting from an upstream patch or internal enhancement.service/ecsIssues and PRs that pertain to the ecs service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions