hashicorp/terraform · error

A managed resource address is required. Importing into a…

Error message

A managed resource address is required. Importing into a data resource is not allowed.

What it means

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.

Solutions

  1. Ensure the import target address refers to a managed resource block, not a data source.
  2. Check that your configuration has a 'resource "type" "name"' block matching the import address.
  3. Remove any 'data.' prefix from the import address.
  4. Verify the resource address spelling matches an existing managed resource in your .tf files.

Example fix

// before: importing into a data source
terraform import data.aws_ami.example ami-12345
// error: A managed resource address is required.

// after: import into a managed resource
terraform import aws_instance.example i-12345
Defensive patterns

Strategy: validation

Validate before calling

// Validate the import address is a managed resource, not a data source:
// if strings.HasPrefix(addr, "data.") {
//     return fmt.Errorf("cannot import into data source %s; use a managed resource", addr)
// }
// exec.Command("terraform", "import", addr, id)

Prevention

When it happens

Trigger: 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.

Common situations: 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'.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/726242e73ca14acf. Report an issue: GitHub.

Appendix: 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 backend

View on GitHub (pinned to d32a084675)