# Real-time Pricing

MechCloud displays cost information directly in the plan output before any infrastructure changes are applied. This enables cost-aware infrastructure decisions during development rather than discovering costs after deployment.

### Overview

When generating an execution plan, MechCloud calculates and displays comprehensive cost information for Azure resources that have associated costs.

### Supported Billing Models

| Model                | How it appears in the plan                    | Examples                                                |
| -------------------- | --------------------------------------------- | ------------------------------------------------------- |
| Usage-based (hourly) | Hourly rate + max monthly total (730 hours)   | Virtual Machines, Load Balancers, Public IPs            |
| Storage (GB-month)   | Monthly rate + total when size is known       | Managed Disks (Premium SSD, Standard SSD, Standard HDD) |
| Consumption-based    | Rate only (actual usage unknown at plan time) | Data transfer, Storage transactions, Bandwidth          |

#### Usage-Based Charges (Price + Cost)

For resources with **predictable usage patterns**, MechCloud shows both price rates and calculated costs:

* Virtual Machine compute hours
* Public IP address hours
* Load Balancer hours
* Managed Disk storage (GB-Mo)

Example: A `Standard_B1s` VM shows `price: $0.01040/Hrs, monthly: $7.59`

**Azure Spot Pricing**: For all regular Virtual Machines, MechCloud displays both regular and spot pricing in the plan output. This helps users evaluate potential cost savings by using spot instances when suitable for their workloads.

Example: `vm1 (action: create, price: $0.01040/Hrs, monthly: $7.59, spot-price: $0.00312/Hrs, spot-monthly: $2.28)`

#### Consumption-Based Charges (Price Only)

For resources with **variable consumption**, MechCloud shows pricing rates but cannot calculate costs without actual usage data:

* Data transfer (GB)
* Storage transactions
* Bandwidth usage
* Application Gateway data processing

**Example**: Storage account transaction pricing shown as `Price (Transactions - price: $0.0004/10K transactions)`

### Cost Change Tracking

MechCloud displays cost change percentages for all resource actions, helping you understand the financial impact of infrastructure changes.

#### Create Actions

When creating new resources, the cost change is **+100%** (from $0 to the new cost):

```
vm1 (action: create, price: $0.01040/Hrs, monthly: $7.59, change: +100%)
```

#### Update Actions

When modifying existing resources, the change percentage reflects the actual cost difference.

**Example: Resizing a VM from Standard\_B2s to Standard\_B1s**

```
vm1 (action: update, price: $0.01040/Hrs, monthly: $7.59, change: -50%)
```

The -50% change indicates a 50% cost reduction from the previous `Standard_B2s` configuration.

**Example: Upgrading disk from Standard HDD to Premium SSD**

```
data_disk (action: update, monthly: $19.71, change: +150%)
```

The +150% change shows the cost increase from Standard HDD to Premium SSD tier.

#### Delete Actions

When deleting resources, the cost change is **-100%** (from current cost to $0):

```
vm1 (action: delete, price: $0.00/Hrs, monthly: $0.00, change: -100%)
```

### Plan Output Examples

#### Virtual Machine (Usage-Based Charges)

Virtual Machines have predictable usage patterns, so MechCloud calculates and displays actual hourly and monthly costs.

**Creating a regular Virtual Machine:**

```yaml
resources:
  - type: Microsoft.Compute/virtualMachines
    name: vm1
    props:
      location: "eastus"
      hardware_profile:
        vm_size: "Standard_B1s"
      storage_profile:
        image_reference:
          publisher: "Canonical"
          offer: "0001-com-ubuntu-server-jammy"
          sku: "22_04-lts-gen2"
          version: "latest"
        os_disk:
          create_option: "FromImage"
          managed_disk:
            storage_account_type: "Standard_LRS"
          disk_size_gb: 30
      os_profile:
        computer_name: "vm1"
        admin_username: "ubuntu"
        linux_configuration:
          disable_password_authentication: true
          ssh:
            public_keys:
              - path: "/home/ubuntu/.ssh/authorized_keys"
                key_data: "ssh-rsa AAAA..."
      network_profile:
        network_interfaces:
          - id: "ref:nic1"
```

**Plan output:**

```
vm1 (action: create, price: $0.01040/Hrs, monthly: $7.59, spot-price: $0.00312/Hrs, spot-monthly: $2.28, change: +100%)
=> Compute (price: $0.01040/Hrs, monthly: $7.59, spot-price: $0.00312/Hrs, spot-monthly: $2.28)
=> Storage (OS Disk - Standard HDD S4 32GB - monthly: $1.54)
```

The plan shows:

* **Regular price**: `$0.01040/Hrs` - calculated hourly cost for Standard\_B1s VM
* **Regular monthly**: `$7.59` - estimated monthly cost (hourly × 730 hours)
* **Spot price**: `$0.00312/Hrs` - spot instance hourly cost for comparison
* **Spot monthly**: `$2.28` - estimated monthly spot cost
* **OS Disk**: `$1.54/month` - Standard HDD S4 tier (32GB)
* **Change**: `+100%` - new resource, going from $0 to $7.59/month

**Key Feature**: MechCloud displays spot pricing alongside regular pricing for all Virtual Machines. This encourages users to evaluate spot instances when suitable for their workloads, potentially saving up to 70-90% on compute costs.

**Creating a spot Virtual Machine:**

```yaml
resources:
  - type: Microsoft.Compute/virtualMachines
    name: spot_vm1
    props:
      location: "eastus"
      priority: "Spot"
      eviction_policy: "Deallocate"
      billing_profile:
        max_price: -1  # Pay up to regular price
      hardware_profile:
        vm_size: "Standard_B1s"
      storage_profile:
        image_reference:
          publisher: "Canonical"
          offer: "0001-com-ubuntu-server-jammy"
          sku: "22_04-lts-gen2"
          version: "latest"
        os_disk:
          create_option: "FromImage"
          managed_disk:
            storage_account_type: "Standard_LRS"
          disk_size_gb: 30
      os_profile:
        computer_name: "spotvm1"
        admin_username: "ubuntu"
        linux_configuration:
          disable_password_authentication: true
          ssh:
            public_keys:
              - path: "/home/ubuntu/.ssh/authorized_keys"
                key_data: "ssh-rsa AAAA..."
      network_profile:
        network_interfaces:
          - id: "ref:nic1"
```

**Plan output:**

```
spot_vm1 (action: create, spot-price: $0.00312/Hrs, spot-monthly: $2.28, change: +100%)
=> Compute (spot-price: $0.00312/Hrs, spot-monthly: $2.28)
=> Storage (OS Disk - Standard HDD S4 32GB - monthly: $1.54)
```

For spot instances, only spot pricing is shown since the VM will use spot capacity. The +100% change indicates a new resource.

#### Managed Disk (Storage-Based Charges)

Managed Disks demonstrate storage-based pricing where costs are calculated based on the provisioned tier size.

**Creating a Premium SSD Managed Disk:**

```yaml
resources:
  - type: Microsoft.Compute/disks
    name: data_disk
    props:
      location: "eastus"
      sku:
        name: "Premium_LRS"
      disk_size_gb: 128
      creation_data:
        create_option: "Empty"
```

**Plan output:**

```
data_disk (action: create, monthly: $19.71, change: +100%)
=> Storage (Premium SSD P10 128GB - monthly: $19.71)
```

The plan shows:

* **Monthly cost**: `$19.71` - Premium SSD P10 tier (128GB capacity)
* **Tier**: P10 - Azure automatically maps 128GB to P10 tier
* **Change**: `+100%` - new resource

**Azure Disk Tier Mapping**: Azure Managed Disks use fixed-size tiers. When you specify `disk_size_gb: 128`, Azure provisions a P10 disk (128GB capacity) and charges the P10 tier rate, not a per-GB rate.

**Creating a Standard SSD Managed Disk:**

```yaml
resources:
  - type: Microsoft.Compute/disks
    name: standard_disk
    props:
      location: "eastus"
      sku:
        name: "StandardSSD_LRS"
      disk_size_gb: 256
      creation_data:
        create_option: "Empty"
```

**Plan output:**

```
standard_disk (action: create, monthly: $19.20, change: +100%)
=> Storage (Standard SSD E15 256GB - monthly: $19.20)
```

The Standard SSD E15 tier (256GB) costs `$19.20/month`, significantly less than Premium SSD for workloads that don't require premium performance.

#### Public IP Address (Usage-Based Charges)

Public IP addresses have hourly charges based on SKU type.

**Creating a Basic Public IP:**

```yaml
resources:
  - type: Microsoft.Network/publicIPAddresses
    name: public_ip1
    props:
      location: "eastus"
      sku:
        name: "Basic"
      public_ip_allocation_method: "Dynamic"
```

**Plan output:**

```
public_ip1 (action: create, price: $0.00400/Hrs, monthly: $2.92, change: +100%)
```

**Creating a Standard Public IP:**

```yaml
resources:
  - type: Microsoft.Network/publicIPAddresses
    name: public_ip2
    props:
      location: "eastus"
      sku:
        name: "Standard"
      public_ip_allocation_method: "Static"
```

**Plan output:**

```
public_ip2 (action: create, price: $0.00500/Hrs, monthly: $3.65, change: +100%)
```

Standard SKU costs more but provides additional features like zone redundancy and static allocation.

#### Load Balancer (Usage-Based Charges)

Load Balancers have hourly charges based on SKU type.

**Creating a Basic Load Balancer:**

```yaml
resources:
  - type: Microsoft.Network/loadBalancers
    name: lb1
    props:
      location: "eastus"
      sku:
        name: "Basic"
      frontend_ip_configurations:
        - name: "frontend1"
          public_ip_address:
            id: "ref:public_ip1"
```

**Plan output:**

```
lb1 (action: create, price: $0.02500/Hrs, monthly: $18.25, change: +100%)
```

**Creating a Standard Load Balancer:**

```yaml
resources:
  - type: Microsoft.Network/loadBalancers
    name: lb2
    props:
      location: "eastus"
      sku:
        name: "Standard"
      frontend_ip_configurations:
        - name: "frontend1"
          public_ip_address:
            id: "ref:public_ip2"
```

**Plan output:**

```
lb2 (action: create, price: $0.02500/Hrs, monthly: $18.25, change: +100%)
```

### Supported Resources

MechCloud provides real-time pricing for the following Azure resource types:

| Offering                    | Resource Type           |
| --------------------------- | ----------------------- |
| Microsoft.Compute           | Virtual Machine         |
|                             | Managed Disk            |
| Microsoft.ContainerService  | AKS Managed Cluster     |
| Microsoft.ContainerInstance | Container Instance      |
| Microsoft.Network           | Public IP Address       |
|                             | Load Balancer           |
|                             | Application Gateway     |
|                             | NAT Gateway             |
|                             | VPN Gateway             |
|                             | Azure Firewall          |
|                             | Front Door              |
|                             | DNS Zone                |
| Microsoft.Sql               | SQL Database            |
| Microsoft.DBforMySQL        | Flexible Server         |
| Microsoft.DBforPostgreSQL   | Flexible Server         |
| Microsoft.DocumentDB        | Cosmos DB Account       |
| Microsoft.Cache             | Azure Cache for Redis   |
| Microsoft.Storage           | Storage Account         |
| Microsoft.ServiceBus        | Service Bus Namespace   |
| Microsoft.EventHub          | Event Hub Namespace     |
| Microsoft.Web               | App Service Plan        |
|                             | Functions (Consumption) |

For detailed pricing examples, see [Examples (Resources With Cost)](https://docs.mechcloud.io/cloud-computing/stateless-iac/azure/examples-resources-with-cost).

### Regional Pricing

Costs vary by Azure region. MechCloud automatically applies region-specific pricing.

Example - `Standard_B1s` pricing:

```yaml
# eastus
vm_size: "Standard_B1s"  # $0.01040/Hr, $7.59/month

# westeurope
vm_size: "Standard_B1s"  # $0.01144/Hr, $8.35/month
```

### Using Pricing Data

#### Compare Configurations

```yaml
# Option A - Burstable series
vm_size: "Standard_B2s"  # $0.0416/Hr, $30.37/month

# Option B - General purpose
vm_size: "Standard_D2s_v3"  # $0.096/Hr, $70.08/month
```

#### Compare Disk Types

```yaml
# Option A - Standard HDD (S10 tier)
sku:
  name: "Standard_LRS"
disk_size_gb: 128  # $5.89/month

# Option B - Premium SSD (P10 tier)
sku:
  name: "Premium_LRS"
disk_size_gb: 128  # $19.71/month
```

#### Track Environment Costs

When generating plans for different Resource Contexts:

```
Development environment (context: app-dev)
Monthly cost: $125.43

Production environment (context: app-prod)
Monthly cost: $892.15
```

#### Document Cost Decisions

```yaml
resources:
  - type: Microsoft.Compute/virtualMachines
    name: api-server
    props:
      # Standard_D2s_v3 for consistent CPU performance
      # Cost: +$39.71/month vs Standard_B2s
      # Justified by API latency requirements
      hardware_profile:
        vm_size: "Standard_D2s_v3"
```

### Example Workflow

This example demonstrates how real-time pricing helps optimize infrastructure costs during development.

#### Initial Configuration

```yaml
resources:
  - type: Microsoft.Compute/virtualMachines
    name: web-server
    props:
      hardware_profile:
        vm_size: "Standard_D2s_v3"
      storage_profile:
        os_disk:
          managed_disk:
            storage_account_type: "Premium_LRS"
          disk_size_gb: 128
```

When you generate a plan, MechCloud shows costs for each resource. You can then adjust VM sizes and disk types to optimize costs before deploying.

#### Cost Optimization

By reviewing the pricing information in the plan:

1. **Resize compute**: Change `Standard_D2s_v3` to `Standard_B2s` to reduce VM costs
2. **Adjust disk type**: Change from Premium SSD to Standard SSD if performance allows
3. **Consider spot**: Evaluate spot instances for non-critical workloads

Each configuration change generates a new plan showing updated costs, enabling iterative optimization before any resources are created.

### Best Practices

**Include cost justification in code comments** - Document why specific VM sizes or disk types were chosen.

**Compare costs during code review** - Review cost deltas alongside configuration changes.

**Track cost trends over time** - Save plan outputs to monitor infrastructure cost evolution.

**Use Resource Context for cost isolation** - Separate cost tracking by environment (dev, staging, prod).

**Monitor actual vs estimated costs** - Compare MechCloud estimates against actual Azure bills to refine understanding.

**Understand disk tier pricing** - Azure charges by tier (P10, E15, S20), not exact GB size.

**Evaluate spot instances** - Review spot pricing for workloads that can tolerate interruptions.

### Azure-Specific Considerations

#### Disk Tier Pricing

Unlike per-GB pricing, Azure Managed Disks use fixed-size tiers:

**Premium SSD Tiers**:

* P4 (32GB) - $6.40/month
* P6 (64GB) - $12.29/month
* P10 (128GB) - $19.71/month
* P15 (256GB) - $38.40/month
* P20 (512GB) - $75.78/month

**Standard SSD Tiers**:

* E4 (32GB) - $2.40/month
* E6 (64GB) - $4.80/month
* E10 (128GB) - $9.60/month
* E15 (256GB) - $19.20/month
* E20 (512GB) - $38.40/month

**Standard HDD Tiers**:

* S4 (32GB) - $1.54/month
* S6 (64GB) - $3.01/month
* S10 (128GB) - $5.89/month
* S15 (256GB) - $11.52/month
* S20 (512GB) - $22.53/month

When you specify `disk_size_gb: 100`, Azure provisions the next tier up (e.g., P10 for 128GB) and charges the tier rate.

#### VM Spot Pricing

Azure Spot VMs can save up to 90% compared to regular pricing, but can be evicted when Azure needs capacity. Best for:

* Batch processing jobs
* Development/test environments
* Stateless workloads
* Interruptible computations

#### Regional Price Variations

Azure pricing varies significantly by region. Examples for `Standard_B1s`:

* East US: $0.01040/Hr
* West Europe: $0.01144/Hr
* Southeast Asia: $0.01248/Hr

Always check pricing for your target region during planning.

### Integration with Stateless IaC

Real-time pricing works seamlessly with MechCloud's stateless architecture:

**Fresh pricing every plan** - No stale data from state files

**Accurate cost deltas** - Costs compared against actual current state

**Environment isolation** - Resource Context enables per-environment cost tracking

### Next Steps

* [Examples (Resources With Cost)](https://docs.mechcloud.io/cloud-computing/stateless-iac/azure/examples-resources-with-cost)
* [Authoring Desired State](https://docs.mechcloud.io/cloud-computing/stateless-iac/azure/authoring-desired-state)
