First Config
The config file (infrastructure.ts by default) is a TypeScript module that defines your infrastructure using Kyku resource classes.
Imports
Section titled “Imports”Every resource class is imported from @kykucloud/types:
import { Vpc, Vm, SecurityGroup, LoadBalancer, Database } from '@kykucloud/types';Creating Resources
Section titled “Creating Resources”Each resource takes a config object matching its resource-specific interface:
const vpc = new Vpc({ id: 'vpc-main', // Unique logical ID (used in state) name: 'main-vpc', // Cloud resource name cidr: '10.0.0.0/16', // Provider-native CIDR region: 'us-east', // Abstract region (maps per provider)});The id field is used internally for state tracking and dependency resolution. If omitted, a UUID is generated automatically.
The name field becomes the cloud resource name (optionally prefixed — see Deploy Prefix).
Object References Create Dependencies
Section titled “Object References Create Dependencies”When you assign a resource object to another resource’s property, Kyku creates a dependency edge:
const vm = new Vm({ id: 'vm-web', name: 'web-server', instanceType: 'small', image: 'ubuntu-22.04', network: vpc, // Object ref → Vm depends on Vpc securityGroups: [webSG], // Array of objects → Vm depends on SecurityGroup});This means the VPC is created before the VM, and the VM is destroyed before the VPC.
String references (e.g. network: 'vpc-main') do not create dependency edges — use object references to ensure correct ordering.
The Export
Section titled “The Export”Reusable stacks are plain TypeScript factories that return BaseResource[] — see TypeScript modules.
The module must export a default object:
export default { provider: 'aws', // Default provider for all resources resources: [vpc, webSG, vm, db, lb],};Single Provider
Section titled “Single Provider”export default { provider: 'hetzner', resources: [vpc, vm],};Multi-Provider
Section titled “Multi-Provider”Some resources can use a different provider by setting their provider field:
const awsVm = new Vm({ id: 'vm-aws', name: 'aws-server', provider: 'aws', // ...});
const gcpVm = new Vm({ id: 'vm-gcp', name: 'gcp-server', provider: 'gcp', // ...});
export default { provider: 'aws', // Default providers: { // Named provider configs aws: { region: 'us-east-1' }, gcp: { region: 'us-central1' }, }, resources: [awsVm, gcpVm],};Tags and Labels
Section titled “Tags and Labels”Tags are passed as key-value pairs and mapped to provider-native labels/tags:
new Vm({ id: 'vm-web', name: 'web-server', tags: { environment: 'production', team: 'platform', }, // ...});Full Multi-Resource Example
Section titled “Full Multi-Resource Example”import { Vpc, Vm, SecurityGroup, LoadBalancer, Database } from '@kykucloud/types';
const vpc = new Vpc({ id: 'vpc-main', name: 'main-vpc', cidr: '10.0.0.0/16', region: 'us-east',});
const webSG = new SecurityGroup({ id: 'sg-web', name: 'web-sg', ingress: [ { protocol: 'tcp', fromPort: 80, toPort: 80, sources: ['0.0.0.0/0'] }, { protocol: 'tcp', fromPort: 443, toPort: 443, sources: ['0.0.0.0/0'] }, ],});
const webServer = new Vm({ id: 'vm-web', name: 'web-server', instanceType: 'small', image: 'ubuntu-22.04', network: vpc, securityGroups: [webSG], userData: `#!/bin/bashapt-get updateapt-get install -y nginx`,});
const db = new Database({ id: 'db-main', name: 'app-db', engine: 'postgresql', version: '15', instanceType: 'small', storage: 20, username: 'appuser', vpc: vpc, securityGroups: [webSG],});
const lb = new LoadBalancer({ id: 'lb-web', name: 'web-lb', lbType: 'application', vpc: vpc, listeners: [ { port: 80, protocol: 'http', targets: [{ vm: webServer.outputs.instanceId, port: 80 }], }, ],});
export default { provider: 'aws', resources: [vpc, webSG, webServer, db, lb] };