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.61k stars 9k forks source link

[Bug]: aws_ecs_task_definition throws error when task definition is deleted outside of terraform #29749

Open nwsparks opened 1 year ago

nwsparks commented 1 year ago

Terraform Core Version

1.3.4

AWS Provider Version

4.38.0

Affected Resource(s)

aws_ecs_task_definition

Expected Behavior

it should recreate the missing task definition

Actual Behavior

plans/applies throw an error Error: ClientException: Unable to describe task definition.

Relevant Error/Panic Output Snippet

data.aws_subnet.subnets["subnet-"]: Read complete after 0s [id=subnet-]
data.aws_subnet.subnets["subnet-"]: Read complete after 0s [id=subnet-]
data.aws_subnet.subnets["subnet-"]: Read complete after 0s [id=subnet-]
╷
│ Error: ClientException: Unable to describe task definition.
│
│   with aws_ecs_task_definition.service,
│   on test.tf line 27, in resource "aws_ecs_task_definition" "service":
│   27: resource "aws_ecs_task_definition" "service" {
│
╵

Terraform Configuration Files

resource "aws_ecs_task_definition" "service" {
  family = "test"
  container_definitions = jsonencode([
    {
      name      = "test"
      image     = "service-first"
      cpu       = 10
      memory    = 512
      essential = true
      portMappings = [
        {
          containerPort = 80
          hostPort      = 80
        }
      ]
    }
  ])
}

Steps to Reproduce

  1. create a new task def via terraform
  2. in the aws console unregister it
  3. change the drop down to display unregistered tasks and choose to delete the task
  4. change the drop down to display delete in progress tasks and wait 30-60+ minutes
  5. once the task disappears from delete in progress run terraform plan

Debug Output

No response

Panic Output

No response

Important Factoids

the delete task definition functionality is new, https://aws.amazon.com/blogs/containers/announcing-amazon-ecs-task-definition-deletion/

before this there was no way to delete task definitions.

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

sarmad-ali-9 commented 1 year ago

I'm getting the same error since morning. I did exactly whats mentioned in steps to reproduce section. And now because of this error our whole staging environment is effected.

caseyoneill commented 1 year ago

I am seeing the same issue with Terraform 1.4.0 and AWS 4.58.0. The task definitions were manually deleted outside of terraform. The only way to get things working again was to manually delete the task definitions from my Terraform state file by running:

terraform state rm <module>.aws_ecs_task_definition.aws-ecs-task

bploetz commented 1 year ago

Ran into this too (we recently started deleting old task defs as part of our release process) and @caseyoneill 's suggestion fixes the problem (you obviously need to recreate the resource you delete from the state file).

JoseAFerrer commented 1 year ago

Hi, everyone! I see the issue and understand the suggestion by @caseyoneill, but sadly I get an error while removing that: Error saving the state: unsupported attribute "arn_without_revision" It's weird because I am not using that attribute anywhere in the code... Any idea?

bhargavpanth commented 1 year ago

Seem to be running into this issue. In my case, I am running tests (using Terratests to spin up ECS on Localstack). The only way to get around this issue seems to be by removing the task definition from the state. I am using Terraform v1.4.4 on darwin_arm64`. Is this a case of an un-updated Terraform version?

david-hodgson-at-sky commented 5 months ago

Also hit this issue following on from having having an issue with partially deleted task definitions (an AWS "feature" - state goes to DELETE_IN_PROGRESS and it's not deleted).

DorisEckel8412 commented 4 months ago

Hi, we run in the same error message, after deleting 1 version of the task definition outside of terraform. We use version 1.7.3.

justintilson-steeltoad commented 3 months ago

I'm getting the same error with

Terraform: 1.7.4 cdktf: 0.20.3 @cdktf/provider-aws: 19.6.0

I'm completely blocked. I can't destroy or create resources in my workspace now.

I'm using Terraform Cloud.

jani4865 commented 1 month ago

I am getting same error with aws provider 5.16.2