hashicorp/terraform · error
A managed resource address is required. Importing into a dat
Error message
A managed resource address is required. Importing into a data resource is not allowed.
What it means
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.
Source
Thrown at internal/command/import.go:72
traversal, travDiags := hclsyntax.ParseTraversalAbs(traversalSrc, "<import-address>", hcl.Pos{Line: 1, Column: 1})
diags = diags.Append(travDiags)
if travDiags.HasErrors() {
c.registerSynthConfigSource("<import-address>", traversalSrc) // so we can include a source snippet
c.showDiagnostics(diags)
c.Ui.Info(importCommandInvalidAddressReference)
return 1
}
addr, addrDiags := addrs.ParseAbsResourceInstance(traversal)
diags = diags.Append(addrDiags)
if addrDiags.HasErrors() {
c.registerSynthConfigSource("<import-address>", traversalSrc) // so we can include a source snippet
c.showDiagnostics(diags)
c.Ui.Info(importCommandInvalidAddressReference)
return 1
}
if addr.Resource.Resource.Mode != addrs.ManagedResourceMode {
diags = diags.Append(errors.New("A managed resource address is required. Importing into a data resource is not allowed."))
c.showDiagnostics(diags)
return 1
}
if !c.dirIsConfigPath(parsedArgs.ConfigPath) {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "No Terraform configuration files",
Detail: fmt.Sprintf(
"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.",
parsedArgs.ConfigPath,
),
})
c.showDiagnostics(diags)
return 1
}
// Load the backendView on GitHub (pinned to c9def3e214)
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.
Example fix
# before $ terraform import data.aws_ami.ubuntu ami-12345 # after $ terraform import aws_instance.web i-12345
Defensive patterns
Strategy: type-guard
Validate before calling
// Reject data-resource addresses before invoking 'terraform import'.
func isManagedAddress(addr string) bool {
return !strings.HasPrefix(addr, "data.")
} Type guard
// Type-guard over the parsed address mode (Go).
func isManagedResource(addr addrs.AbsResourceInstance) bool {
return addr.Resource.Resource.Mode == addrs.ManagedResourceMode
} Prevention
- 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.
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- empty state name
- Attempted to initialize pluggable state with an empty string
- missing state name
- the secret name %v is invalid, {validationErrors} This is a
- missing state name
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/726242e73ca14acf.
Report an issue: GitHub.