jckuester / awsweeper

A tool for cleaning your AWS account
Mozilla Public License 2.0
469 stars 45 forks source link

Pop up `panic: can't use ElementIterator on null value` error #110

Open showerlee opened 4 years ago

showerlee commented 4 years ago

Hi @jckuester , recently I got the following error while cleanup ecs resource. the weird thing is current region doesn't have any ecs cluster, but it still happens each time.

    Type: aws_ecs_cluster
    Found: 1

        Id:     arn:aws:ecs:ap-southeast-2:xxxxxxxxxxxx:cluster/default

    ---

   • TOTAL NUMBER OF RESOURCES THAT WOULD BE DELETED: 1
   • USER WILL NOT BE ASKED FOR CONFIRMATION (FORCE MODE)
   • STARTING TO DELETE RESOURCES
panic: can't use ElementIterator on null value

goroutine 194 [running]:
github.com/zclconf/go-cty/cty.Value.ElementIterator(0x5f98800, 0xc00048b450, 0x0, 0x0, 0x7, 0x0)
    /home/jan/go/pkg/mod/github.com/zclconf/go-cty@v1.4.0/cty/value_ops.go:1038 +0x11a
github.com/zclconf/go-cty/cty.Value.AsValueMap(0x5f98800, 0xc00048b450, 0x0, 0x0, 0x1)
    /home/jan/go/pkg/mod/github.com/zclconf/go-cty@v1.4.0/cty/value_ops.go:1243 +0xfe
github.com/jckuester/terradozer/pkg/provider.enableForceDestroyAttributes(0x5f98800, 0xc00048b450, 0x0, 0x0, 0x203000, 0x203000, 0x203000, 0xf4a6622f9a8800fb)
    /home/jan/go/pkg/mod/github.com/jckuester/terradozer@v0.1.2/pkg/provider/provider.go:236 +0xf7
github.com/jckuester/terradozer/pkg/provider.TerraformProvider.DestroyResource.func1(0x4c0da0)
    /home/jan/go/pkg/mod/github.com/jckuester/terradozer@v0.1.2/pkg/provider/provider.go:200 +0x86
github.com/hashicorp/terraform/helper/resource.Retry.func1(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/jan/go/pkg/mod/github.com/hashicorp/terraform@v0.12.25/helper/resource/wait.go:22 +0x5e
github.com/hashicorp/terraform/helper/resource.(*StateChangeConf).WaitForState.func1(0xc00926e720, 0xc0001d4540, 0xc000850600, 0xc007e240c0, 0xc0082242d0, 0xc0082242c8)
    /home/jan/go/pkg/mod/github.com/hashicorp/terraform@v0.12.25/helper/resource/state.go:103 +0x298
created by github.com/hashicorp/terraform/helper/resource.(*StateChangeConf).WaitForState
    /home/jan/go/pkg/mod/github.com/hashicorp/terraform@v0.12.25/helper/resource/state.go:80 +0x1bf

The awsweeper policy is following with latest version v.0.10.1

aws_ecs_cluster:
  - tags:
      NOT(Owner): .*

Could you help to take a look?

jckuester commented 4 years ago

Hi @showerlee again,

thanks for another bug report. I guess know what the issue is and will fix it:

I assume that your ECS cluster is in state INACTIVE (which means it has already been deleted). Can you please check? AWSweeper should not list INACTIVE ECS clusters, but it currently does - I will fix that. I also will fix the panic. What happen there is that I assume that we won't see already deleted resources in the deletion stage (with nil state) and don't check for nil there.

jckuester commented 4 years ago

Just letting you know that the error you encountered will be fixed in the following PR and is released soon: https://github.com/jckuester/awsweeper/pull/116. Thanks for you patience.

jckuester commented 4 years ago

Fix is released in v0.10.2. Please let me know if that fixes the issue.