{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/import.go#L54-L90","documentation":"Returned at import.go:72 when the address argument to 'terraform import' resolves to a data resource (addr.Resource.Resource.Mode != addrs.ManagedResourceMode) instead of a managed resource. The import command can only import into managed resources; data sources are read-only and cannot be import targets.","triggerScenarios":"Running 'terraform import data_type.name <id>' — the address parser (addrs.ParseAbsResourceInstance) successfully parses the address but its mode is addrs.DataResourceMode. import.go:70-72 checks the mode and rejects data resources.","commonSituations":"Confusing a data source with a managed resource; typos in the resource address (e.g., 'data.' prefix accidentally included); attempting to import into a resource block declared with 'data' instead of 'resource'.","solutions":["Ensure the import target address refers to a managed resource block, not a data source.","Check that your configuration has a 'resource \"type\" \"name\"' block matching the import address.","Remove any 'data.' prefix from the import address.","Verify the resource address spelling matches an existing managed resource in your .tf files."],"exampleFix":"// before: importing into a data source\nterraform import data.aws_ami.example ami-12345\n// error: A managed resource address is required.\n\n// after: import into a managed resource\nterraform import aws_instance.example i-12345","handlingStrategy":"validation","validationCode":"// Validate the import address is a managed resource, not a data source:\n// if strings.HasPrefix(addr, \"data.\") {\n//     return fmt.Errorf(\"cannot import into data source %s; use a managed resource\", addr)\n// }\n// exec.Command(\"terraform\", \"import\", addr, id)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Double-check import addresses do not start with 'data.'.","Ensure the import target has a matching 'resource' block in configuration.","Review the resource address against your .tf files before importing."],"tags":["terraform","cli","import","resource-mode","argument-validation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}