heat_template_version: ocata

resources:

###################################################################################################
# NETWORKS
###################################################################################################

  soho_net:
    type: OS::Neutron::Net
    properties:
      name: soho_net

###################################################################################################
# SUBNETS
###################################################################################################

  # Single subnet implementation.
  # IP pools for soho: 192.168.0.0/24
  soho_subnet:
    type: OS::Neutron::Subnet
    depends_on: soho_net
    properties:
      name: soho_subnet
      cidr: 192.168.0.0/24
      dns_nameservers: [10.50.255.254,]
      network_id: { get_resource: soho_net }

#########################################################
# ROUTERS - one port & interface per subnet per router
#########################################################

  # SOHO ROUTER #########################################
  soho_router:
    type: OS::Neutron::Router
    properties:
      name: soho_router
      # External gateway added for internet access
      external_gateway_info: { network: public }

  soho_router_interface:
    type:  OS::Neutron::RouterInterface
    depends_on: soho_router
    properties:
      router_id: { get_resource: soho_router }
      subnet: { get_resource: soho_subnet }

###################################################################################################
# PORTS
###################################################################################################

  instance_port:
    type:  OS::Neutron::Port
    properties:
      network: { get_resource: soho_net }

###################################################################################################
# INSTANCES
###################################################################################################

  my_instance:
    type: OS::Nova::Server
    properties:
      name: my-comp
      image: Debian-Stretch
      flavor: cy.medium
      networks:
        - port: { get_resource: instance_port }
      user_data_format: RAW
      user_data: |
        #!/bin/bash

        # Add hostname to /etc/hosts
        echo 127.0.0.1 $(hostname) >> /etc/hosts
        # Add special domain to /etc/hosts
        #echo "127.0.0.1 www.evil.tgt" >> /etc/hosts

        # Setup users and passwords
        echo "root:toor" | chpasswd        # Change password for root, if required
        useradd student -m -U -s /bin/bash # First, add the user and give them a shell
        usermod -aG sudo student           # Give them sudo priviledges, if required
        echo "student:password" | chpasswd # Update the user password.

        # Establish a proximal proxy cache for faster downloads
        PROXY_UP=`ping -c1 -W3 pkg-cache.bbh.cyberschool.army.mil >/dev/null 2>&1 ; echo $?`
        if [ $PROXY_UP -lt 1 ]; then
            # Old (internal only): http://acng.bbh.cyberschool.army.mil:3142
            echo 'Acquire::http::proxy "http://pkg-cache.bbh.cyberschool.army.mil:3142";' > /etc/apt/apt.conf.d/02proxy
        fi

        # Update, Upgrade & Install any required packages
        apt -y update
        apt -y upgrade
        ##################################################
        # In this section insert the packages you need
        # apt-get -y install <pkg-name>, <pkg-name>, ...
        # e.g. python, ftp, telnet, samba, nmap, curl, ...
        #
        ##################################################
        updatedb
        mandb

        ##################################################
        # Add any special host configurations here
        #
        # wget/curl publicly/locally available files/programs to then execute/use
        #
        # configure iptables rules
        #
        # configure SSH
        # sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
        ##################################################