Adopt existing infrastructure into OpenTofu or Terraform state. Use when importing unmanaged resources, reconciling state with real infrastructure, auditing what already exists, or migrating manually created resources into IaC. In OpenTofu environments, prefer manual discovery plus import blocks or tofu import; do not default to Terraform Search or terraform query unless the user explicitly works in Terraform and that feature is available.
This repository is OpenTofu-first. That changes the default import workflow.
OpenTofu supports import blocks and the tofu import command, but Terraform Search and terraform query are Terraform-specific features and should not be the default path here.
tofu import.In this repository, assume step 2 unless the user says otherwise.
Use the provider's CLI, console, or API to discover the existing objects and their import IDs.
Examples:
Create the resource or module address where the object should live long-term.
for_each key, or count index.resource "aws_instance" "web" {
# Fill in the intended managed configuration.
}
Use import blocks when the import should be visible in version control and reviewed with the rest of the configuration.
import {
to = aws_instance.web
id = "i-1234567890abcdef0"
}
resource "aws_instance" "web" {
# Fill in the intended managed configuration.
}
In this repo:
cd terraform
tofu init
tofu plan -var-file=terraform.tfvars
tofu apply -var-file=terraform.tfvars
For a focused import review, a plain tofu plan is also acceptable when no tfvars are needed.
After import:
tofu importUse the CLI command when you need a one-off state attachment and do not want to keep an import block in the codebase.
tofu import aws_instance.web i-1234567890abcdef0
tofu import 'aws_iam_user.users["alice"]' alice
tofu import module.network.aws_vpc.main vpc-12345678
Prefer import blocks instead when the import is part of a code reviewable migration.
For many similar resources:
If you need a repeatable template for manual discovery, read references/MANUAL-IMPORT.md.
for_each, import directly into the keyed address.count, import directly into the indexed address.When adopting resources into this repo:
terraform/servers, server_defaults, and compartment-alias modelIf the user explicitly wants Terraform Search or terraform query, stop and confirm the runtime first.
Only use that path when all of the following are true:
Otherwise, fall back to the manual OpenTofu workflow.
terraform query in an OpenTofu repo.Before finishing an import/adoption task in this repository:
tofu fmt -recursive from terraform/ if HCL changed.tofu validate.tofu plan or tofu plan -var-file=terraform.tfvars to confirm the imported object matches the intended configuration.