Import Resources
Use kyku import to bring existing cloud resources under Kyku management without recreating them.
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) |
Examples
Section titled “Examples”# Import an existing AWS VPCkyku import Vpc vpc-0abc123def456 --name=main-vpc
# Import an existing EC2 instancekyku import Vm i-0xyz789abc123 --name=web-server
# Import an existing GCP Cloud SQL instancekyku import Database my-instance --name=app-db
# Import an existing Hetzner networkkyku import Vpc 12224210 --name=main-networkHow It Works
Section titled “How It Works”- Kyku creates a stub resource in memory with the given type and cloud ID
- Calls
provider.readState(stub, cloudId)to read the current cloud state - Writes the resource into the state file with its full config and outputs
- On subsequent
planruns, the resource shows as no-op (existing)
State before: emptyState after: Vm "i-0xyz789" tracked (no changes needed)Prerequisites
Section titled “Prerequisites”- 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
Adding to Config
Section titled “Adding to Config”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.
Supported Resource Types
Section titled “Supported Resource Types”All resource types support import: Vpc, Vm, SecurityGroup, LoadBalancer, Database, Identity, Role, SshKey, Bucket, DnsZone, DnsRecord, TargetGroup, Custom.
Unsupported Resources
Section titled “Unsupported Resources”Resources that throw UnsupportedFeatureError on the provider (e.g., TargetGroup on GCP, Database on Hetzner) cannot be imported.
State File After Import
Section titled “State File After Import”{ "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" } }}Import vs Create
Section titled “Import vs Create”| 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 |
Caveats
Section titled “Caveats”- Config alignment: The resource’s config in your
infrastructure.tsshould 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
--nameexplicitly.