heat_template_version: 2013-05-23

description: |
  This is a Heat template to deploy a server with LAMP

parameter_groups:
- label: Server Settings
  parameters:
  - server_hostname
  - image
  - flavor

- label: phpMyAdmin Settings
  parameters:
  - phpmyadmin_user

- label: rax-dev-params
  parameters:
  - kitchen
  - chef_version

parameters:
  server_hostname:
    label: Server Name
    description: Hostname to use for setting the server name.
    type: string
    default: web
    constraints:
    - length:
        min: 1
        max: 64
    - allowed_pattern: "^[a-zA-Z0-9]([a-zA-Z0-9.-])*$"
      description: |
        Must begin with a letter or number and be alphanumeric or '-' and '.'

  image:
    label: Operating System
    description: |
      Required: Server image used for all servers that are created as a part of
      this deployment.
    type: string
    default: CentOS 6.5 (PVHVM)
    constraints:
    - allowed_values:
      - CentOS 6.5 (PVHVM)
      - Red Hat Enterprise Linux 6.5 (PVHVM)
      - Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
      - Ubuntu 12.04 LTS (Precise Pangolin)
      - Debian 7 (Wheezy) (PVHVM)
      description: Must be a supported operating system.

  flavor:
    label: Server Size
    description: |
      Required: Rackspace Cloud Server flavor to use. The size is based on the
      amount of RAM for the provisioned server.
    type: string
    default: 1 GB General Purpose v1
    constraints:
    - allowed_values:
      - 1 GB General Purpose v1
      - 2 GB General Purpose v1
      - 4 GB General Purpose v1
      - 8 GB General Purpose v1
      - 15 GB I/O v1
      - 30 GB I/O v1
      description: |
        Must be a valid Rackspace Cloud Server flavor for the region you have
        selected to deploy into.

  phpmyadmin_user:
    label: Username
    description: "Username for phpMyAdmin logins."
    type: string
    default: serverinfo
    constraints:
    - allowed_pattern: "^(.){1,16}$"
      description: |
        Must be shorter than 16 characters, this is due to MySQL's maximum
        username length.

  kitchen:
    description: URL for the kitchen to use
    type: string
    default: https://github.com/rackspace-orchestration-templates/lamp

  chef_version:
    description: Version of chef client to use
    type: string
    default: 11.12.8

resources:

  ssh_key:
    type: "OS::Nova::KeyPair"
    properties:
      name: { get_param: "OS::stack_id" }
      save_private_key: true

  mysql_root_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  mysql_repl_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  mysql_debian_password:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  phpmyadmin_pass:
    type: "OS::Heat::RandomString"
    properties:
      length: 16
      sequence: lettersdigits

  linux_server:
    type: "Rackspace::Cloud::Server"
    properties:
      name: { get_param: server_hostname }
      flavor: { get_param: flavor }
      image: { get_param: image }
      key_name: { get_resource: ssh_key }
      config_drive: "true"
      metadata:
        rax-heat: { get_param: "OS::stack_id" }
    metadata:
      foo: bar
      baz: qux

  linux_setup:
    type: "OS::Heat::ChefSolo"
    depends_on: linux_server
    properties:
      username: root
      private_key: { get_attr: [ssh_key, private_key] }
      host: { get_attr: [linux_server, accessIPv4] }
      kitchen: { get_param: kitchen }
      chef_version: { get_param: chef_version }
      node:
        mysql:
          server_root_password: { get_attr: [mysql_root_password, value] }
          server_repl_password: { get_attr: [mysql_repl_password, value] }
          server_debian_password: { get_attr: [mysql_debian_password, value] }
        phpmyadmin:
          pass: { get_attr: [phpmyadmin_pass, value] }
          user: { get_param: phpmyadmin_user }
        run_list: ["recipe[LAMP]"]

outputs:
  private_key:
    description: SSH Private Key
    value: { get_attr: [ssh_key, private_key] }

  server_ip:
    description: Server IP
    value: { get_attr: [linux_server, accessIPv4] }

  phpmyadmin_url:
    description: phpMyAdmin URL
    value:
      str_replace:
        template: "http://%server_ip%/phpmyadmin"
        params:
          "%server_ip%": { get_attr: [linux_server, accessIPv4] }

  phpmyadmin_user:
    description: phpMyAdmin User
    value: { get_param: phpmyadmin_user }

  phpmyadmin_password:
    description: phpMyAdmin Password
    value: { get_attr: [phpmyadmin_pass, value] }

  mysql_root_password:
    description: MySQL Root Password
    value: { get_attr: [mysql_root_password, value] }
