Instance (Virtual Machine)

Creating a virtual machine with minimal parameters

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-0bc691261a82b32bc
      instance_type: t3.nano
      security_group_ids:
        - "ref:sg_web"

Creating a spot virtual machine

resources:
  - type: aws_ec2_launch_template
    name: template1
    props:
      launch_template_name: "template1"
      launch_template_data:
        instance_type: "t3.nano"
        image_id: "ami-0bc691261a82b32bc"
        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, spot-price: $0.00160/Hrs, spot-monthly: $1.19)

Creating an on-demand virtual machine using launch template

resources:
  - type: aws_ec2_launch_template
    name: template1
    props:
      launch_template_name: "template1"
      launch_template_data:
        instance_type: "t3.nano"
        image_id: "ami-0bc691261a82b32bc"

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

Example price for above configuration

template1 (action: create)
vm1 (action: create, price: $0.00520/Hrs, monthly: $3.87, spot-price: $0.00160/Hrs, spot-monthly: $1.19)

Last updated

Was this helpful?