Skip to content

Importing Existing Resources

Adoption brings an object that exists in the cloud, but not in state, under management: one made by hand or by another tool, state that was lost, a move between workspaces. Two ways in:

import {} block import tool
Lives in the configuration (root module) nowhere — a tool call
Adopts at the up plan, which diffs the configuration against the real object its own import-only round, as tofu import; nothing else is planned
Reviewable the plan says importing, and one apply adopts and reconciles the adoption only; the next up shows the diff

Prefer the block: the adoption is part of the plan the user approves for everything else, and a block left behind afterwards is inert. Reach for the tool to get objects into state before anything else is planned. Writing the block is authoring (skill_authoring); the configuration must declare the target resource either way — Turf generates no configuration.

import({ targets: [{ addr: "aws_s3_bucket.logs", id: "my-logging-bucket" }] })
→ { convergence_id, outcome: "awaiting_approval", plan: { uri, digest, import: 1, … }, … }
apply({ convergence_id: "…", plan_digest: "…" })
→ { outcome: "converged", … }
  • Each target names a resource instance address — module-prefixed for one in a module (module.rg.azapi_resource.this) — and exactly one of id (the provider’s import ID) or identity (the attributes of the provider’s identity schema, which provider_describe shows).
  • The round reads each target and nothing else: no other object is read or changed. It stops at its approval point like any round; apply writes the objects into state. A refusal of any target fails the plan, so nothing is imported at all.
  • The provider instance is the resource’s own, as with tofu import: a resource with provider = azurerm.west is read through that aliased block. There is no provider argument.

Then bring the object under management:

  1. Examine what was imported — state_list({ include_values: true }), or show({ what: "state" }).
  2. Adjust the resource’s block to the desired configuration (skill_authoring) and run up: the diff shows any difference between the object and the configuration.
  3. Present that plan; apply it if the user approves.

To adopt the object as it is, write configuration matching the imported attributes: the plan is a no-op.

An import-only round refuses, naming the target:

  • a target the configuration does not declare (“resource address … does not exist in the configuration”), a data source, a target named twice, or one without exactly one of id/identity;
  • an address state already holds (“Resource already managed by OpenTofu”);
  • a target whose resource cannot be planned yet (“cannot import … this round: … it is deferred”);
  • any configuration with a moved block (“an import-only round changes nothing but its imports; plan and apply normally first”).
import {
to = aws_s3_bucket.logs
id = "my-logging-bucket" # or identity = { … }
}

up adopts the object and diffs the configuration against it: the change reads no-op or update and carries importing, and plan.import counts it. apply adopts first and updates after. A plan may also replace the object it adopts — point that out before approving: it is the one case where an import takes an object away.

  • The block goes in the root module; to may name a nested address, carry dynamic keys, and the block may for_each.
  • id/identity must not be sensitive or ephemeral. Differs from Terraform: an id, to key or for_each not known at plan defers the resource (resource_config_unknown) and the import happens in a later round, where Terraform refuses.
  • An import into an address a moved block vacates this round is refused: apply the move first, then import. An import into an address state already holds does nothing, so a block left in place is safe.

The id format is the provider’s:

Resource type Format Example
aws_instance instance ID i-1234567890abcdef0
aws_s3_bucket bucket name my-bucket
azurerm_resource_group resource ID /subscriptions/…/resourceGroups/my-rg
google_compute_instance project/zone/name my-project/us-central1-a/my-instance
Error Cause Resolution
“Cannot import non-existent remote object” A wrong ID, or the object is gone Check the ID format; if it is gone, plan a create instead
“Resource already managed by OpenTofu” The address is taken The object at that address is already managed
“Configuration for import target does not exist” No resource block for the target Write the block first

Turf™ is a trademark of Turf LLC. Terraform® is a trademark of HashiCorp. Ansible® is a trademark of Red Hat, LLC, registered in the United States and other countries. Helm®, Kubernetes®, Prometheus® and OpenTelemetry® are registered trademarks, and Jaeger™ is a trademark, of the Linux Foundation. OpenTofu® and Model Context Protocol® are registered trademarks of LF Projects, LLC. All other trademarks are the property of their respective owners. Turf is not affiliated with, endorsed by, or sponsored by HashiCorp, IBM, Red Hat, the Linux Foundation, LF Projects or the OpenTofu project.

© 2026 Turf LLC. Free for individuals, education and small businesses within the Community limits, under the Turf Community Edition License 1.0. Government and larger organizations need a commerciallicense.turf.build · Discord ·GitHub