heat_template_version: 2014-10-16

description: OpenShift cluster server

parameters:

  name:
    type: string
    label: Name
    description: Name

  cluster_env:
    type: string
    label: Cluster environment
    description: Environment of the cluster

  cluster_id:
    type: string
    label: Cluster ID
    description: Identifier of the cluster

  type:
    type: string
    label: Type
    description: Type master or node

  subtype:
    type: string
    label: Sub-type
    description: Sub-type compute or infra for nodes, default otherwise
    default: default

  key_name:
    type: string
    label: Key name
    description: Key name of keypair

  image:
    type: string
    label: Image
    description: Name of the image

  flavor:
    type: string
    label: Flavor
    description: Name of the flavor

  net:
    type: string
    label: Net ID
    description: Net resource

  net_name:
    type: string
    label: Net name
    description: Net name

  subnet:
    type: string
    label: Subnet ID
    description: Subnet resource

  secgrp:
    type: comma_delimited_list
    label: Security groups
    description: Security group resources

  floating_network:
    type: string
    label: Floating network
    description: Network to allocate floating IP from

outputs:

  name:
    description: Name of the server
    value: { get_attr: [ server, name ] }

  private_ip:
    description: Private IP of the server
    value:
      get_attr:
        - server
        - addresses
        - { get_param: net_name }
        - 0
        - addr

  floating_ip:
    description: Floating IP of the server
    value:
      get_attr:
        - server
        - addresses
        - { get_param: net_name }
        - 1
        - addr

resources:

  server:
    type: OS::Nova::Server
    properties:
      name:      { get_param: name }
      key_name:  { get_param: key_name }
      image:     { get_param: image }
      flavor:    { get_param: flavor }
      networks:
        - port:  { get_resource: port }
      user_data: { get_resource: config }
      user_data_format: RAW
      metadata:
        environment: { get_param: cluster_env }
        clusterid: { get_param: cluster_id }
        host-type: { get_param: type }
        sub-host-type:    { get_param: subtype }

  port:
    type: OS::Neutron::Port
    properties:
      network: { get_param: net }
      fixed_ips:
        - subnet: { get_param: subnet }
      security_groups: { get_param: secgrp }

  floating-ip:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network: { get_param: floating_network }
      port_id: { get_resource: port }

  config:
    type: OS::Heat::CloudConfig
    properties:
      cloud_config:
        disable_root: true

        hostname: { get_param: name }

        system_info:
          default_user:
            name: openshift
            sudo: ["ALL=(ALL) NOPASSWD: ALL"]

        write_files:
          - path: /etc/sudoers.d/00-openshift-no-requiretty
            permissions: 440
            # content: Defaults:openshift !requiretty
            # Encoded in base64 to be sure that we do not forget the trailing newline or
            # sudo will not be able to parse that file
            encoding: b64
            content: RGVmYXVsdHM6b3BlbnNoaWZ0ICFyZXF1aXJldHR5Cg==
