---
heat_template_version: 2018-08-31

parameters:
  private_network:
    type: string
  key_name:
    type: string
    label: Key Name
    description: Name of key-pair to be used for compute instance
    default: maclef
  flavorname:
    type: string
    default: a1-ram2-disk20-perf1
  image:
    type: string
    default: Debian 11.3 bullseye
  name:
    type: string
  servergroup:
    type: string
  pool:
    type: string
    default: none
  allowed_address_pairs:
    type: json
    default: []
  admin_pass: 
    type: string
    default: none
  userdata:
    type: string
    default: |
      #cloud-config
      packages:
       - python-minimal
  security_groups:
    type: comma_delimited_list
    default: "default"

conditions:
  create_pool_member:
    not:
      equals:
        - {get_param: pool}
        - "none"
resources:
  # random password for Windows VMs
  random_password:
    type: OS::Heat::RandomString
    properties:
      length: 8

  port:
    type: OS::Neutron::Port
    properties:
      network: {get_param: private_network}
      security_groups: {get_param: security_groups}
      allowed_address_pairs: {get_param: allowed_address_pairs}

  instance:
    type: OS::Nova::Server
    properties:
      name: {get_param: name}
      flavor: {get_param: flavorname}
      image: {get_param: image}
      key_name: {get_param: key_name}
      networks: [port: {get_resource: port}]
      scheduler_hints:
        group: {get_param: servergroup}
      user_data_format: RAW
      user_data: {get_param: userdata}
      metadata:
        admin_pass: { get_attr: [random_password, value] }

outputs:
  internal_ip:
    description: Internal IP of the host
    value: {get_attr: [instance, first_address]}
  server_id:
    description: ID of instance
    value: {get_attr: [instance, name]}
  admin_pass:
    description: For Windows servers only, login password
    value: {get_attr: [random_password, value]}
