azure.vm

Virtual Machine Resource

example:

Stop all running VMs

policies:
  - name: stop-running-vms
    resource: azure.vm
    filters:
      - type: instance-view
        key: statuses[].code
        op: in
        value_type: swap
        value: PowerState/running
    actions:
      - type: stop
example:

Start all VMs

policies:
  - name: start-vms
    resource: azure.vm
    actions:
      - type: start
example:

Restart all VMs

policies:
  - name: start-vms
    resource: azure.vm
    actions:
      - type: restart
example:

Resize specific VM by name

policies:
  - name: resize-vm
    resource: azure.vm
    filters:
      - type: value
        key: name
        op: eq
        value_type: normalize
        value: fake_vm_name
    actions:
      - type: resize
        vmSize: Standard_A2_v2
example:

Delete specific VM by name

policies:
  - name: delete-vm
    resource: azure.vm
    filters:
      - type: value
        key: name
        op: eq
        value_type: normalize
        value: fake_vm_name
    actions:
      - type: delete
example:

Find all VMs with a Public IP address

policies:
  - name: vms-with-public-ip
    resource: azure.vm
    filters:
      - type: network-interface
        key: 'properties.ipConfigurations[].properties.publicIPAddress.id'
        value: not-null
example:

This policy will find all VMs that have Percentage CPU usage >= 75% over the last 72 hours

policies:
  - name: busy-vms
    resource: azure.vm
    filters:
      - type: metric
        metric: Percentage CPU
        op: ge
        aggregation: average
        threshold: 75
        timeframe: 72
example:

This policy will find all VMs that have Percentage CPU usage <= 1% over the last 72 hours, mark for deletion in 7 days

policies:
  - name: delete-unused-vms
    resource: azure.vm
    filters:
      - type: metric
        metric: Percentage CPU
        op: le
        aggregation: average
        threshold: 1
        timeframe: 72
     actions:
      - type: mark-for-op
        op: delete
        days: 7

Filters

advisor-recommendation

Filter resources by Azure Advisor Recommendations

Select all categories with ‘all’

example:

policies:
  - name: disks-with-cost-recommendations
    resource: azure.disk
    filters:
      - type: advisor-recommendation
        category: Cost
        key: '[].properties.recommendationTypeId'
        op: contains
        value: '48eda464-1485-4dcf-a674-d0905df5054a'
properties:
  category:
    type: string
  default:
    type: object
  key:
    type: string
  op:
    enum:
    - eq
    - equal
    - ne
    - not-equal
    - gt
    - greater-than
    - ge
    - gte
    - le
    - lte
    - lt
    - less-than
    - glob
    - regex
    - regex-case
    - in
    - ni
    - not-in
    - contains
    - difference
    - intersect
    - mod
  type:
    enum:
    - advisor-recommendation
  value:
    oneOf:
    - type: array
    - type: string
    - type: boolean
    - type: number
    - type: 'null'
  value_from:
    additionalProperties: 'False'
    properties:
      expr:
        oneOf:
        - type: integer
        - type: string
      format:
        enum:
        - csv
        - json
        - txt
        - csv2dict
      headers:
        patternProperties:
          ? ''
          : type: string
        type: object
      query:
        type: string
      url:
        type: string
    required:
    - url
    type: object
  value_path:
    type: string
  value_regex:
    type: string
  value_type:
    enum:
    - age
    - integer
    - expiration
    - normalize
    - size
    - cidr
    - cidr_size
    - swap
    - resource_count
    - expr
    - unique_size
    - date
    - version
    - float
required:
- category
- type

network-interface

properties:
  default:
    type: object
  key:
    type: string
  op:
    enum:
    - eq
    - equal
    - ne
    - not-equal
    - gt
    - greater-than
    - ge
    - gte
    - le
    - lte
    - lt
    - less-than
    - glob
    - regex
    - regex-case
    - in
    - ni
    - not-in
    - contains
    - difference
    - intersect
    - mod
  type:
    enum:
    - network-interface
  value:
    oneOf:
    - type: array
    - type: string
    - type: boolean
    - type: number
    - type: 'null'
  value_from:
    additionalProperties: 'False'
    properties:
      expr:
        oneOf:
        - type: integer
        - type: string
      format:
        enum:
        - csv
        - json
        - txt
        - csv2dict
      headers:
        patternProperties:
          ? ''
          : type: string
        type: object
      query:
        type: string
      url:
        type: string
    required:
    - url
    type: object
  value_path:
    type: string
  value_regex:
    type: string
  value_type:
    enum:
    - age
    - integer
    - expiration
    - normalize
    - size
    - cidr
    - cidr_size
    - swap
    - resource_count
    - expr
    - unique_size
    - date
    - version
    - float
required:
- type

Actions

poweroff

Parent base class for filters and actions.

properties:
  type:
    enum:
    - poweroff
required:
- type

resize

Change a VM’s size

example:

Resize specific VM by name

policies:
  - name: resize-vm
    resource: azure.vm
    filters:
      - type: value
        key: name
        op: eq
        value_type: normalize
        value: fake_vm_name
    actions:
      - type: resize
        vmSize: Standard_A2_v2
properties:
  type:
    enum:
    - resize
  vmSize:
    type: string
required:
- vmSize
- type

restart

Parent base class for filters and actions.

properties:
  type:
    enum:
    - restart
required:
- type

start

Parent base class for filters and actions.

properties:
  type:
    enum:
    - start
required:
- type

stop

Parent base class for filters and actions.

properties:
  type:
    enum:
    - stop
required:
- type