From 34515c7b509949ea4edb55e62ccd9ddf174285fe Mon Sep 17 00:00:00 2001
From: Alex Hayes <alex.hayes@roi.com.au>
Date: Fri, 12 Dec 2014 09:20:09 +1100
Subject: [PATCH] Add state 'mysql.dev' that provides support for installing
 MySQL development libraries and header files.

---
 README.rst          | 9 +++++++++
 mysql/defaults.yaml | 7 +++++++
 mysql/dev.sls       | 7 +++++++
 mysql/init.sls      | 6 ++++++
 pillar.example      | 5 +++++
 5 files changed, 34 insertions(+)
 create mode 100644 mysql/dev.sls

diff --git a/README.rst b/README.rst
index 88daca4..4d42fe0 100644
--- a/README.rst
+++ b/README.rst
@@ -82,6 +82,15 @@ Remove the database called ``test``, normally created as part of a default
 MySQL installation.  This state is **not** included as part of the meta-state
 above as this name may conflict with a real database.
 
+``mysql.dev``
+------------------------------
+
+Install the MySQL development libraries and header files.
+
+.. note::
+    Note that this state is not installed by the mysql meta-state unless you set
+    your pillar data accordingly. 
+
 Updating the supported parameters
 =================================
 
diff --git a/mysql/defaults.yaml b/mysql/defaults.yaml
index 8a3a16b..f21ea79 100644
--- a/mysql/defaults.yaml
+++ b/mysql/defaults.yaml
@@ -6,6 +6,7 @@ Ubuntu:
   service: mysql
   python: python-mysqldb
   debconf_utils: debconf-utils
+  dev: libmysqlclient-dev
   config:
     file: /etc/mysql/my.cnf
     sections:
@@ -50,6 +51,7 @@ Debian:
   service: mysql
   python: python-mysqldb
   debconf_utils: debconf-utils
+  dev: libmysqlclient-dev
   config:
     file: /etc/mysql/my.cnf
     sections:
@@ -92,6 +94,7 @@ CentOS:
   client: mysql
   service: mysqld
   python: MySQL-python
+  dev: mysql-devel
   config:
     file: /etc/my.cnf
     sections:
@@ -110,6 +113,7 @@ RedHat:
   client: mysql
   service: mysqld
   python: MySQL-python
+  dev: mysql-devel
   config:
     file: /etc/my.cnf
     sections:
@@ -128,6 +132,7 @@ Amazon:
   client: mysql
   service: mysqld
   python: MySQL-python
+  dev: mysql-devel
   config:
     file: /etc/my.cnf
     sections:
@@ -146,6 +151,7 @@ Gentoo:
   client: dev-db/mysql
   service: mysql
   python: dev-python/mysql-python
+  dev: dev-db/mysqlced
   config:
     file: /etc/mysql/my.cnf
     sections:
@@ -227,6 +233,7 @@ FreeBSD:
   client: mysql56-client
   service: mysql-server
   python: pymysql
+  dev: mysql56-server
   config:
     file: /usr/local/etc/my.cnf
     sections:
diff --git a/mysql/dev.sls b/mysql/dev.sls
new file mode 100644
index 0000000..e111b70
--- /dev/null
+++ b/mysql/dev.sls
@@ -0,0 +1,7 @@
+{% from "mysql/defaults.yaml" import rawmap with context %}
+{%- set mysql = salt['grains.filter_by'](rawmap, grain='os', merge=salt['pillar.get']('mysql:server:lookup')) %}
+
+mysql_dev:
+  pkg:
+    - installed
+    - name: {{ mysql.dev }}
diff --git a/mysql/init.sls b/mysql/init.sls
index ae2d9d2..3a44d2b 100644
--- a/mysql/init.sls
+++ b/mysql/init.sls
@@ -7,10 +7,16 @@
       {%- endfor -%}
 {% endmacro %}
 
+{% set mysql_dev = salt['pillar.get']('mysql:dev:install', False) %}
+
 include:
   - mysql.server
   - mysql.database
   - mysql.user
+{% if mysql_dev %}
+  - mysql.dev
+{% endif %}
+  
 
 {% if (db_states|length() + user_states|length()) > 0 %}
 extend:
diff --git a/pillar.example b/pillar.example
index e6cf278..026b595 100644
--- a/pillar.example
+++ b/pillar.example
@@ -60,3 +60,8 @@ mysql:
     service: mysql-service
     config: /etc/mysql/my.cnf
     python: python-mysqldb
+
+  # Install MySQL headers
+  dev:
+  	# Install dev package - defaults to False
+  	install: False
\ No newline at end of file
-- 
GitLab