> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formae.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a virtual machine

> An Azure infrastructure pattern, deployed with formae.

An Ubuntu virtual machine reachable over SSH, with its own networking. One forma
provisions the resource group, a virtual network and subnet, a network security
group that allows SSH, a static public IP, a network interface, and the virtual
machine itself.

```mermaid theme={"languages":{"custom":["/languages/pkl.json"]}}
flowchart LR
  target["vm-target-azure"]:::tgt

  subgraph stack["azure-vm-eastus"]
    direction LR
    rg["Resource group"]:::res
    vnet["Virtual network"]:::res
    subnet["Subnet"]:::res
    nsg["Network security group"]:::res
    pip["Public IP"]:::res
    nic["Network interface"]:::res
    vm["Virtual machine"]:::res

    rg --> vnet
    rg --> subnet
    vnet --> subnet
    rg --> nsg
    rg --> pip
    rg --> nic
    subnet --> nic
    pip --> nic
    nsg --> nic
    rg --> vm
    nic --> vm
  end

  target --> stack

  classDef tgt fill:#FF8201,stroke:#B25900,color:#ffffff
  classDef res fill:#FFF3E6,stroke:#FF8201,color:#02024B
  style stack fill:#ffffff,stroke:#02024B,stroke-width:2px,stroke-dasharray:6 4,color:#02024B
```

**Deploy.** Export your SSH public key first, then apply the example forma.
formae orders the resources by their dependencies automatically, so the network
interface wires up the subnet, public IP, and security group before the machine
boots:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-azure/virtual-machine/main.pkl
```

**Verify.** Once the command completes, the machine is under management:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae inventory resources --query="type:AZURE::Compute::VirtualMachine"
```

**Tear down.** Remove everything the forma created:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae destroy \
  /opt/pel/formae/examples/formae-plugin-azure/virtual-machine/main.pkl
```

The full forma is in the
[virtual-machine example](https://github.com/platform-engineering-labs/formae-plugin-azure/tree/main/examples/virtual-machine).
