Had a really weird error today while applying some Terraform to a dev environment from my local machine:

│ Warning: Failed to decode resource from state
│
│ Error decoding "module.something.aws_ecs_service.mirror" from prior state: a number is required
╵
╷
│ Error: a number is required
│
│   with module.something.aws_ecs_service.mirror,
│   on .terraform/modules/something/terraform/modules/something_v2/mirror.tf line 100, in resource "aws_ecs_service" "mirror":
│  100: resource "aws_ecs_service" "mirror" {
│

Couldn’t find anything with a quick Google, so I went with the trusty TF_LOG=DEBUG and found this:

2024-07-22T11:12:05.339+0100 [ERROR] provider.terraform-provider-aws_v5.59.0_x5: Response contains error diagnostic: diagnostic_summary="a number is required" tf_proto_version=5.6 tf_resource_type=aws_ecs_service diagnostic_attribute=AttributeName("volume_configuration").ElementKeyInt(0).AttributeName("managed_ebs_volume").ElementKeyInt(0).AttributeName("throughput") diagnostic_severity=ERROR tf_req_id=f55d3aa4-473e-a57e-d5d2-03094402500a tf_provider_addr=registry.terraform.io/hashicorp/aws @caller=github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/diag/diagnostics.go:58 @module=sdk.proto diagnostic_detail= tf_rpc=UpgradeResourceState timestamp=2024-07-22T11:12:05.339+0100
2024-07-22T11:12:05.339+0100 [ERROR] vertex "module.something.aws_ecs_service.mirror" error: a number is required
2024-07-22T11:12:05.339+0100 [ERROR] vertex "module.something.aws_ecs_service.mirror (expand)" error: a number is required

Which seemed to imply I was missing a value for throughput on the EBS volume which is odd because it’s optional. So I thought I’d take a look at the current values:

💠 v1.5.7 › tf state show module.something.aws_ecs_service.mirror
Failed to marshal state to json: a number is requiredThe state file is empty. No resources are represented.

Wat? Tried to import it, but it said I couldn’t so I removed it from the state and tried to re-import it:

│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "module.something.aws_ecs_service.mirror", the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id
│ is correct and that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.
╵

Watwat?

But the service was definitely there in the ECS cluster, happily chugging away.

I ended up force deleting the service and rerunning the Terraform and it seemed to be ok. Assuming the state got mangled during an interrupted run in CI.