oxid import

Import existing infrastructure into the Oxid state database from Terraform state files or by provider resource ID.

Usage

oxid import <address> <id>
oxid import --state-file <path>

The import command brings existing infrastructure under Oxid management. You can import from a Terraform .tfstate file (bulk import) or import individual resources by their provider ID.

Import from .tfstate File

Import all resources from an existing Terraform state file:

$ oxid import --state-file terraform.tfstate

Importing resources from terraform.tfstate...
  Imported: aws_vpc.main (vpc-0a1b2c3d4e5f67890)
  Imported: aws_subnet.public[0] (subnet-0abc123def456)
  Imported: aws_subnet.public[1] (subnet-0def456abc789)
  Imported: aws_security_group.web (sg-0123456789abcdef)
  Imported: aws_instance.api (i-0abcdef1234567890)
  Imported: aws_s3_bucket.logs (acme-logs-prod)

Successfully imported 6 resources.
NoteThis is the same import that runs automatically during oxid init when a terraform.tfstate file is detected. Use this command to import from a state file at a different path.

Import Individual Resource

Import a single resource by specifying its Oxid address and provider-specific ID:

$ oxid import aws_s3_bucket.existing my-existing-bucket

Importing aws_s3_bucket.existing...
  aws_s3_bucket.existing: Imported (id: my-existing-bucket)

The resource must already be declared in your .tf configuration. Oxid contacts the provider to read the resource's current attributes and stores them in state.

# First, declare the resource in your .tf file:
resource "aws_s3_bucket" "existing" {
  bucket = "my-existing-bucket"
}

# Then import it:
oxid import aws_s3_bucket.existing my-existing-bucket

Common Import IDs

Each provider uses different ID formats. Here are some common examples:

# AWS
oxid import aws_instance.web i-0abcdef1234567890
oxid import aws_s3_bucket.data my-bucket-name
oxid import aws_vpc.main vpc-0a1b2c3d4e5f67890
oxid import aws_iam_role.app my-role-name
oxid import aws_security_group.web sg-0123456789abcdef

# GCP
oxid import google_compute_instance.web projects/my-proj/zones/us-central1-a/instances/web-01
oxid import google_storage_bucket.data my-bucket-name

# Azure
oxid import azurerm_resource_group.main /subscriptions/xxx/resourceGroups/my-rg

Flags

FlagDescriptionDefault
--state-file <path>Path to a Terraform .tfstate file to import all resources from.-

After Import

After importing, run oxid plan to verify that your configuration matches the imported state. Any differences will show as planned changes:

$ oxid import aws_s3_bucket.data my-data-bucket
$ oxid plan

No changes. Infrastructure is up to date.
TipIf the plan shows unexpected changes after import, update your .tf configuration to match the actual resource attributes. This is normal when first adopting resources.