# Instance (Virtual Machine)

### Creating a virtual machine with minimal parameters

{% hint style="warning" %}
You can generate similar template from MechCloud AWS agent using below prompts (one at a time) -\
\
create a security group named 'sg\_web' which allows traffic on port 443 form '223.223.223.100/32' port only. its description should be 'Allow HTTPS from private ip'.

\--------------------------------------------------------------------------------------------------------------------

create an ec2 instance named 'web1' with following details -\
image - ami-0bc691261a82b32bc\
instance type - t3.nano\
security groupd id - 'ref:sg\_web'
{% endhint %}

```
resources:
  - name: sg_web
    type: aws_ec2_security_group
    props:
      group_name: sg_web
      group_description: "Allow HTTPS from private ip"
      security_group_ingress:
        - ip_protocol: tcp
          from_port: 443
          to_port: 443
          cidr_ip: {{CURRENT_IP}}/32
  - name: web1
    type: aws_ec2_instance
    props:
      image_id: "{{ Image|arm64_ubuntu_24_04 }}"
      instance_type: t4g.small
      security_group_ids:
        - "ref:sg_web"
```

#### Example price for above configuration

```
sg_web (action: create)
web1 (action: create, monthly: $4.51, change: +100%)
=> Price (Compute - price: $0.0052/Hrs, monthly: $3.87, spot-price: $0.0012/Hrs, spot-monthly: $0.89)
=> Volume 1 (/dev/sda1 - monthly: $0.64)
  => Price (Storage cost (gp3) - price: $0.08/GB-Mo, quantity: 8, monthly: $0.64)
  => Price (IOPS - monthly: $0.00)
    => Tier 1 (First 3000 IOPS-Mo - price: $0.00/IOPS-Mo, quantity: 3000, monthly: $0.00)
  => Price (Throughput - monthly: $0.00)
    => Tier 1 (First 125 MiBps-mo - price: $0.00/MiBps-mo, quantity: 125, monthly: $0.00)
```

### Creating a virtual machine with additional volumes

```
resources:
  - name: sg_web
    type: aws_ec2_security_group
    props:
      group_name: sg_web
      group_description: "Allow HTTPS from private ip"
      security_group_ingress:
        - ip_protocol: tcp
          from_port: 443
          to_port: 443
          cidr_ip: 223.223.223.100/32
  - name: web1
    type: aws_ec2_instance
    props:
      image_id: ami-0ecb62995f68bb549
      instance_type: t3.nano
      security_group_ids:
        - "ref:sg_web"
      block_device_mappings:
        - device_name: /dev/xvda  # Root volume
          ebs:
            volume_size: 30
            volume_type: gp3
            iops: 3100
            throughput: 150
        - device_name: /dev/xvdb  # Additional volume 1
          ebs:
            volume_size: 100
            volume_type: gp2
```

#### Example price for above configuration

```
sg_web (action: create)
web1 (action: create, monthly: $17.77, change: +100%)
=> Price (Compute - price: $0.0052/Hrs, monthly: $3.87, spot-price: $0.0012/Hrs, spot-monthly: $0.89)
=> Volume 1 (/dev/sda1 - monthly: $3.90)
  => Price (Storage cost (gp3) - price: $0.08/GB-Mo, quantity: 30, monthly: $2.40)
  => Price (IOPS - monthly: $0.50)
    => Tier 1 (First 3000 IOPS-Mo - price: $0.00/IOPS-Mo, quantity: 3000, monthly: $0.00)
    => Tier 2 (Over 3000 IOPS-Mo - price: $0.005/IOPS-Mo, quantity: 100, monthly: $0.50)
  => Price (Throughput - monthly: $1.00)
    => Tier 1 (First 125 MiBps-mo - price: $0.00/MiBps-mo, quantity: 125, monthly: $0.00)
    => Tier 2 (Over 125 MiBps-mo - price: $0.04/MiBps-mo, quantity: 25, monthly: $1.00)
=> Volume 2 (/dev/sdf - monthly: $10.00)
  => Price (Storage cost (gp2) - price: $0.10/GB-Mo, quantity: 100, monthly: $10.00)
```

### Creating a virtual machine with free trial (t4g.small)

{% hint style="info" %}
**Free Trial display:** The `t4g.small` instance type qualifies for AWS Free Trial (750 hours/month until Dec 2026). Free trial info is shown in the **plan header** (not as a pricing dimension) because it applies at the AWS account level, not per resource. This avoids confusion when multiple `t4g.small` instances exist in the desired state.
{% endhint %}

```
resources:
  - name: sg_web
    type: aws_ec2_security_group
    props:
      group_name: sg_web
      group_description: "Allow HTTPS from private ip"
      security_group_ingress:
        - ip_protocol: tcp
          from_port: 443
          to_port: 443
          cidr_ip: 223.223.223.100/32
  - name: arm_vm1
    type: aws_ec2_instance
    props:
      image_id: ami-0ecb62995f68bb549
      instance_type: t4g.small
      security_group_ids:
        - "ref:sg_web"
```

#### Example plan output

```
sg_web (action: create)
arm_vm1 (action: create, monthly: $12.56, change: +100%, Free Trial (Dec 2026) (Account - free-hours: 750, monthly-discount: $12.26))
  => Price (Compute - price: $0.0168/Hrs, monthly: $12.26, spot-price: $0.0050/Hrs, spot-monthly: $3.72)
  => Volume 1 (/dev/sda1 - monthly: $0.64)
    => Price (Storage cost (gp3) - price: $0.08/GB-Mo, quantity: 8, monthly: $0.64)
    => Price (IOPS - monthly: $0.00)
      => Tier 1 (First 3000 IOPS-Mo - price: $0.00/IOPS-Mo, quantity: 3000, monthly: $0.00)
    => Price (Throughput - monthly: $0.00)
      => Tier 1 (First 125 MiBps-mo - price: $0.00/MiBps-mo, quantity: 125, monthly: $0.00)
```

### Creating a spot virtual machine

{% hint style="warning" %}
You can generate similar template from MechCloud AWS agent using below prompts (one at a time) -\
\
create a launch template named 'template1' with following details -

image - ami-0bc691261a82b32bc

instance type - t3.nano\
market type - spot

\--------------------------------------------------------------------------------------------------------------------

create an ec2 instance named 'spot\_vm1' using 'ref:template1' launch template id and version 1 of this template
{% endhint %}

```
resources:
  - type: aws_ec2_launch_template
    name: template1
    props:
      launch_template_name: "template1"
      launch_template_data:
        instance_type: "t3.nano"
        image_id: "ami-0ecb62995f68bb549"
        instance_market_options:
          market_type: "spot"

  - type: aws_ec2_instance
    name: spot_vm1
    props:
      launch_template:
        launch_template_id: "ref:template1"
        version: "1"
```

#### Example price for above configuration

```
template1 (action: create)
spot_vm1 (action: create, monthly: $1.53, change: +100%)
=> Price (Compute - spot-price: $0.0012/Hrs, spot-monthly: $0.89)
=> Volume 1 (/dev/sda1 - monthly: $0.64)
  => Price (Storage cost (gp3) - price: $0.08/GB-Mo, quantity: 8, monthly: $0.64)
  => Price (IOPS - monthly: $0.00)
    => Tier 1 (First 3000 IOPS-Mo - price: $0.00/IOPS-Mo, quantity: 3000, monthly: $0.00)
  => Price (Throughput - monthly: $0.00)
    => Tier 1 (First 125 MiBps-mo - price: $0.00/MiBps-mo, quantity: 125, monthly: $0.00)
```
