Excellent example of this in:

https://github.com/saltstack/salt-cloud/blob/develop/saltcloud/deploy/SmartOS.sh