Skip to content

Import Resources

Use kyku import to bring existing cloud resources under Kyku management without recreating them.

Terminal window
kyku import <resourceType> <cloudId> [--name <name>] [-c ./config.ts]
Argument Description
resourceType Resource type (Vpc, Vm, Bucket, DnsZone, etc.)
cloudId Provider-native ID (e.g., vpc-0abc123, i-0xyz789)
--name Optional name for the resource in state
-c Config file path (default: ./infrastructure.ts)
Terminal window
# Import an existing AWS VPC
kyku import Vpc vpc-0abc123def456 --name=main-vpc
# Import an existing EC2 instance
kyku import Vm i-0xyz789abc123 --name=web-server
# Import an existing GCP Cloud SQL instance
kyku import Database my-instance --name=app-db
# Import an existing Hetzner network
kyku import Vpc 12224210 --name=main-network
  1. Kyku creates a stub resource in memory with the given type and cloud ID
  2. Calls provider.readState(stub, cloudId) to read the current cloud state
  3. Writes the resource into the state file with its full config and outputs
  4. On subsequent plan runs, the resource shows as no-op (existing)
State before: empty
State after: Vm "i-0xyz789" tracked (no changes needed)
  • The resource must exist in your cloud account
  • Valid credentials must be configured for the provider
  • The config file (infrastructure.ts) must reference the imported resource if you want Kyku to manage it going forward

After importing, add the resource to your config file so Kyku can detect future drift:

const vpc = new Vpc({
id: 'vpc-main', // Same id used during import
name: 'main-vpc',
cidr: '10.0.0.0/16',
});

You can omit properties that can’t be changed (like cidr for VPCs) — Kyku will use the values from state.

All resource types support import: Vpc, Vm, SecurityGroup, LoadBalancer, Database, Identity, Role, SshKey, Bucket, DnsZone, DnsRecord, TargetGroup, Custom.

Resources that throw UnsupportedFeatureError on the provider (e.g., TargetGroup on GCP, Database on Hetzner) cannot be imported.

{
"vpc-abc": {
"id": "vpc-main",
"type": "Vpc",
"provider": "aws",
"providerId": "vpc-0abc123def456",
"config": {
"cidr": "10.0.0.0/16",
"region": "us-east"
},
"dependencies": [],
"outputs": {
"vpcId": "vpc-0abc123def456"
}
}
}
Aspect Import Create
Cloud resource Already exists Does not exist
Kyku action Reads state, tracks Creates new
Config required Optional (can add later) Required
First plan shows No-op Create
  • Config alignment: The resource’s config in your infrastructure.ts should match what’s in the cloud. Otherwise Kyku will show drift on the next plan.
  • Provider IDs: Kyku stores the provider-native ID (e.g., vpc-0abc123). Do not modify this in the state file.
  • Dependencies: If the imported resource depends on other resources (e.g., a VM in a VPC), import the dependencies first.
  • Name resolution: If the cloud resource was created outside Kyku, ensure its name matches what your config expects, or set --name explicitly.