Docs / Importing into Terraform

Importing existing resources into Terraform

Almost nobody starts from zero. If you've already got pools or subnets in nxip - created by hand, by a script, by a discovery scan, or before you adopted Terraform at all - bring them under Terraform management without deleting and recreating anything. This is the opposite direction fromenvironment discovery: that fills nxip from your cloud accounts, this hands what nxip already knows about to Terraform.

How it works

Three steps: find the resource's real ID, write a resource block whose values match what already exists exactly, then terraform import it. A clean terraform plan afterward -No changes - is what actually proves the config matches reality, not just that the import command itself succeeded.

1. Find the ID

GET /v1/pools or GET /v1/subnets (or the equivalent page in the dashboard) returns each resource's id. That's the only thing terraform import needs.

curl https://nxip.dev/v1/pools -H "x-api-key: $NXIP_API_KEY"

2. Write a matching resource block

The values here have to match what's already there - Terraform doesn't infer them from the import, it diffs your config against the real resource afterward. For a pool, that's straightforward: every attribute is a real, settable value.

resource "nxip_pool" "existing_network" {
  name        = "Corp network (existing)"
  cidr        = "10.50.0.0/16"
  family      = "IPV4"
  environment = "production"
  region      = "us-east-1"
}
nxip_subnet.cidr is different: it's a computed value the provider fills in afterward, not something you set. If the subnet you're importing was carved to a specific size, describe it withprefix_length instead - the same field a fresh nxip_subnet uses to auto-allocate. cidr has no Terraform-settable equivalent, regardless of how the subnet was originally created.
resource "nxip_subnet" "existing_app" {
  environment   = "production"
  region        = "us-east-1"
  family        = "IPV4"
  prefix_length = 24
  name          = "Legacy app subnet"
}

3. Import, then verify with a plan

terraform import nxip_pool.existing_network <pool-id>
terraform import nxip_subnet.existing_app <subnet-id>
terraform plan

No changes. Your infrastructure matches the configuration. is the pass condition. Anything else means the resource block doesn't quite match what's already there yet - fix the config, not the infrastructure, and plan again until it's clean.

Once it's imported, it behaves exactly like anything created through Terraform from the start - seePools, subnets & hierarchy for what happens if you later try to change or remove something that already has children under it.