Instance¶
MltInstance declares a Multipass Ubuntu VM. At deploy time the engine calls multipass launch with the resolved props, and at destroy time it calls multipass delete --purge.
Type: Multipass::Compute::Instance
Import: @cdk-x/multipass
Create-only resource
All props are create-only. Once a VM is launched, the engine will not call update. To change any prop, destroy the VM and redeploy.
Props¶
| Prop | Type | Required | Description |
|---|---|---|---|
name |
string |
✅ | Name of the VM. Must be unique within the Multipass instance. Passed as --name to multipass launch. |
image |
string |
— | Ubuntu image alias or release (e.g. jammy, 22.04, lts). Defaults to the latest LTS if omitted. |
cpus |
number |
— | Number of virtual CPUs. Passed as --cpus. |
memory |
string |
— | Memory allocation (e.g. 2G, 512M). Passed as --memory. |
disk |
string |
— | Disk size (e.g. 20G). Passed as --disk. |
bridged |
boolean |
— | Add a bridged network interface. Equivalent to --bridged. |
timeout |
number |
— | Launch timeout in seconds. Passed as --timeout. |
networks |
InstanceNetwork[] |
— | Host network interfaces to attach at launch time. Each entry maps to a --network argument. |
mounts |
InstanceMount[] |
— | Host-to-guest directory mounts. Each entry maps to a --mount argument. |
cloudInit |
string |
— | Cloud-init user-data string passed to the VM at launch time. Passed as --cloud-init. |
Attribute getters¶
These resolve to runtime values after the VM is created:
| Getter | Type | Resolves to |
|---|---|---|
attrIpAddress |
IResolvable |
The VM's IP address, as returned by multipass info. |
attrSshUser |
IResolvable |
The SSH user inside the VM (typically ubuntu). |
Use these to pass VM details to other constructs:
const vm = new MltInstance(stack, 'Dev', { name: 'dev', image: 'jammy' });
// e.g. pass the IP to another resource
someOtherResource.hostIp = vm.attrIpAddress;
Basic example¶
Translates to:
Example with network, mount, and cloud-init¶
Networks and mounts are plain inline objects — no separate constructs needed:
- Attaches the host interface named
bridgein automatic configuration mode. Runmultipass networksto list interfaces available on your machine. - Mounts
/Users/me/codeon the host at/home/ubuntu/codeinside the VM. - Passed verbatim to
multipass launch --cloud-init. Must be a valid cloud-init YAML string.
Translates to:
multipass launch jammy \
--name dev \
--cpus 4 --memory 4G --disk 20G \
--network bridge,mode=auto \
--mount /Users/me/code:/home/ubuntu/code \
--cloud-init <tmpfile>
See also
- InstanceNetwork — shape of entries in
networks - InstanceMount — shape of entries in
mounts - Overview — how synth and deploy work together