# Virtual Machine

{% hint style="info" %}
These examples assume that linked resources (Network, Subnetwork, Address) already exist in the same environment.
{% endhint %}

{% hint style="info" %}
Regional resources referenced without the `regions/<region>/` prefix will use the region selected in the Stateless IaC UI.
{% endhint %}

## Creating an instance

```yaml
defaults:
  zone: us-central1-a

resources:
  - type: compute.v1.instance
    name: vm1
    props:
      machine_type: machineTypes/e2-micro
      disks:
        - boot: true
          auto_delete: true
          initialize_params:
            # Set to 30GB to maximize the Free Tier limit
            disk_size_gb: 30
            # Set to pd-standard (Standard Persistent Disk) for Free Tier eligibility
            disk_type: diskTypes/pd-standard
            source_image: projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2404-noble-amd64-v20260219

      network_interfaces:
        - subnetwork: subnetworks/subnet1
          access_configs:
            - type: ONE_TO_ONE_NAT
              nat_ip: addresses/vm1-ip.address
              network_tier: STANDARD
```

### Example plan output

```
vm1 (action: create, monthly: $7.31, change: +100%)
  => Compute (vCPU) (price: $0.02181/vCPU/Hr, quantity: 0.25, hours: 730, monthly: $3.98, spot-price: $0.01007/vCPU/Hr, spot-monthly: $1.84)
  => Compute (RAM) (price: $0.00292/GB/Hr, quantity: 1, hours: 730, monthly: $2.13, spot-price: $0.00135/GB/Hr, spot-monthly: $0.99)
  => Boot disk (30GB pd-standard) (monthly: $1.20)
    => Storage (price: $0.04/GiB/Mo, quantity: 30, monthly: $1.20)
```

## Creating an instance with ephemeral public IP

```yaml
defaults:
  zone: us-central1-a

resources:
  - type: compute.v1.instance
    name: vm1
    props:
      machine_type: machineTypes/e2-micro
      disks:
        - boot: true
          auto_delete: true
          initialize_params:
            # Set to 30GB to maximize the Free Tier limit
            disk_size_gb: 30
            # Set to pd-standard (Standard Persistent Disk) for Free Tier eligibility
            disk_type: diskTypes/pd-standard
            source_image: projects/ubuntu-os-cloud/global/images/ubuntu-minimal-2404-noble-amd64-v20260219

      network_interfaces:
        - subnetwork: subnetworks/subnet1
          access_configs:
            - type: ONE_TO_ONE_NAT
              network_tier: STANDARD
```

### Example plan output

```
vm1 (action: create, monthly: $9.93, change: +100%)
  => Compute (vCPU) (price: $0.02181/vCPU/Hr, quantity: 0.25, hours: 730, monthly: $3.98, spot-price: $0.01007/vCPU/Hr, spot-monthly: $1.84)
  => Compute (RAM) (price: $0.00292/GB/Hr, quantity: 1, hours: 730, monthly: $2.13, spot-price: $0.00135/GB/Hr, spot-monthly: $0.99)
  => External IP (ephemeral) (price: $0.00359/Hr, hours: 730, monthly: $2.62)
  => Boot disk (30GB pd-standard) (monthly: $1.20)
    => Storage (price: $0.04/GiB/Mo, quantity: 30, monthly: $1.20)
```
