{"record":{"id":"726242e73ca14acf","repo":"hashicorp/terraform","slug":"a-managed-resource-address-is-required-importing","errorCode":null,"errorMessage":"A managed resource address is required. Importing into a data resource is not allowed.","messagePattern":"A managed resource address is required\\. Importing into a data resource is not allowed\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/import.go","lineNumber":72,"sourceCode":"\ttraversal, travDiags := hclsyntax.ParseTraversalAbs(traversalSrc, \"<import-address>\", hcl.Pos{Line: 1, Column: 1})\n\tdiags = diags.Append(travDiags)\n\tif travDiags.HasErrors() {\n\t\tc.registerSynthConfigSource(\"<import-address>\", traversalSrc) // so we can include a source snippet\n\t\tc.showDiagnostics(diags)\n\t\tc.Ui.Info(importCommandInvalidAddressReference)\n\t\treturn 1\n\t}\n\taddr, addrDiags := addrs.ParseAbsResourceInstance(traversal)\n\tdiags = diags.Append(addrDiags)\n\tif addrDiags.HasErrors() {\n\t\tc.registerSynthConfigSource(\"<import-address>\", traversalSrc) // so we can include a source snippet\n\t\tc.showDiagnostics(diags)\n\t\tc.Ui.Info(importCommandInvalidAddressReference)\n\t\treturn 1\n\t}\n\n\tif addr.Resource.Resource.Mode != addrs.ManagedResourceMode {\n\t\tdiags = diags.Append(errors.New(\"A managed resource address is required. Importing into a data resource is not allowed.\"))\n\t\tc.showDiagnostics(diags)\n\t\treturn 1\n\t}\n\n\tif !c.dirIsConfigPath(parsedArgs.ConfigPath) {\n\t\tdiags = diags.Append(&hcl.Diagnostic{\n\t\t\tSeverity: hcl.DiagError,\n\t\t\tSummary:  \"No Terraform configuration files\",\n\t\t\tDetail: fmt.Sprintf(\n\t\t\t\t\"The directory %s does not contain any Terraform configuration files (.tf or .tf.json). To specify a different configuration directory, use the -config=\\\"...\\\" command line option.\",\n\t\t\t\tparsedArgs.ConfigPath,\n\t\t\t),\n\t\t})\n\t\tc.showDiagnostics(diags)\n\t\treturn 1\n\t}\n\n\t// Load the backend","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/import.go#L54-L90","documentation":"Returned by ImportCommand.Run (import.go:72) when the ADDR argument to 'terraform import' resolves to a data resource rather than a managed resource. Imports can only target managed resources (addr.Resource.Resource.Mode == addrs.ManagedResourceMode); data resources are read-only queries and cannot hold imported state. The check runs after parsing the traversal and validating the address.","triggerScenarios":"Line 71-74: after addrs.ParseAbsResourceInstance succeeds, addr.Resource.Resource.Mode != addrs.ManagedResourceMode -> the error is appended and Run returns 1. Triggered by an address whose first token is 'data.', e.g. 'data.aws_ami.example'.","commonSituations":"Copy-pasting a data-source address instead of the managed resource address; misunderstanding that data sources are queried, not imported; an ADDR with a typo that resolves into the data namespace.","solutions":["Use the managed resource address (no 'data.' prefix): 'terraform import aws_instance.web i-12345'.","Add the managed resource block to config first if it does not exist, then import.","For read-only data, use 'terraform plan' to query the data source rather than import."],"exampleFix":"# before\n$ terraform import data.aws_ami.ubuntu ami-12345\n# after\n$ terraform import aws_instance.web i-12345","handlingStrategy":"type-guard","validationCode":"// Reject data-resource addresses before invoking 'terraform import'.\nfunc isManagedAddress(addr string) bool {\n    return !strings.HasPrefix(addr, \"data.\")\n}","typeGuard":"// Type-guard over the parsed address mode (Go).\nfunc isManagedResource(addr addrs.AbsResourceInstance) bool {\n    return addr.Resource.Resource.Mode == addrs.ManagedResourceMode\n}","tryCatchPattern":null,"preventionTips":["Import only managed resource addresses (no 'data.' prefix).","Add the managed resource block to config before importing.","Use 'terraform state list' to see existing managed addresses for reference."],"tags":["import","resource-address","managed-resource","data-resource","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}