{"record":{"id":"4e011f9cbae2086f","repo":"kubernetes/kops","slug":"unexpected-target-type-for-deletion-t-4e011f","errorCode":null,"errorMessage":"unexpected target type for deletion: %T","messagePattern":"unexpected target type for deletion: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/vpc.go","lineNumber":383,"sourceCode":"\t\treturn terraformWriter.LiteralFromStringValue(*e.ID)\n\t}\n\n\treturn terraformWriter.LiteralProperty(\"aws_vpc\", *e.Name, \"id\")\n}\n\ntype deleteVPCCIDRBlock struct {\n\tvpcID         *string\n\tcidrBlock     *string\n\tassociationID *string\n}\n\nvar _ fi.CloudupDeletion = (*deleteVPCCIDRBlock)(nil)\n\nfunc (d *deleteVPCCIDRBlock) Delete(t fi.CloudupTarget) error {\n\tctx := context.TODO()\n\tawsTarget, ok := t.(*awsup.AWSAPITarget)\n\tif !ok {\n\t\treturn fmt.Errorf(\"unexpected target type for deletion: %T\", t)\n\t}\n\trequest := &ec2.DisassociateVpcCidrBlockInput{\n\t\tAssociationId: d.associationID,\n\t}\n\t_, err := awsTarget.Cloud.EC2().DisassociateVpcCidrBlock(ctx, request)\n\treturn err\n}\n\nfunc (d *deleteVPCCIDRBlock) TaskName() string {\n\treturn \"VPCCIDRBlock\"\n}\n\nfunc (d *deleteVPCCIDRBlock) Item() string {\n\treturn fmt.Sprintf(\"%v: cidr=%v\", *d.vpcID, *d.cidrBlock)\n}\n\nfunc (d *deleteVPCCIDRBlock) DeferDeletion() bool {\n\treturn false // TODO: should we defer this?","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/vpc.go#L365-L401","documentation":"deleteVPCCIDRBlock.Delete is only implemented for the AWS API target. If the deletion runner passes any other target type, the type assertion fails and this error reports the unexpected concrete type. It is an internal invariant violation, not an AWS error.","triggerScenarios":"Delete invoked with a target other than *awsup.AWSAPITarget, e.g. a dry-run/mock target or a new target type wired into deletion without implementing this path.","commonSituations":"Custom forks adding target types; running deletion through a target intended for terraform/cloudspec outputs; internal refactors changing the target passed to deletion actions.","solutions":["Ensure deletion is executed with an AWSAPITarget (real AWS apply/delete path)","If a new target type exists, implement Delete support for it or exclude it from VPC CIDR deletion","Report a bug with the %T output if it occurs in stock kOps"],"exampleFix":"// before: generic target passed\nerr := d.Delete(someGenericTarget)\n// after\nawsTarget, ok := t.(*awsup.AWSAPITarget); if !ok { return fmt.Errorf(...) } // ensure correct target wired","handlingStrategy":"type-guard","validationCode":"if _, ok := target.(*awsup.AWSAPITarget); !ok {\n\treturn errors.New(\"VPC CIDR deletion requires an AWS API target\")\n}","typeGuard":"func isAWSAPITarget(t fi.CloudupTarget) (*awsup.AWSAPITarget, bool) {\n\ta, ok := t.(*awsup.AWSAPITarget)\n\treturn a, ok\n}","tryCatchPattern":"err := d.Delete(t)\nif err != nil && strings.Contains(err.Error(), \"unexpected target type\") {\n\t// bug/invariant violation: log target type and report\n}","preventionTips":["Only run deletions through the standard kops delete flow","When adding custom targets, implement CloudupDeletion for all task deletion types","Add unit tests asserting Delete receives AWSAPITarget","Report unexpected-type errors upstream with the %T value"],"tags":["aws","vpc","cidr","type-assertion","internal"],"backgroundTag":"unexpected-target-type","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}