Terraform is a great orchestration tool, and SaltStack is a great configuration management software. The first one allows you to create resources in the cloud (instances, load balancer, databases, etc) and the second is used to provision the instances. Salt works in a master-agent mode, the agents are called minions. To provision an instance you have to install the salt-minion first. I’ve found two options to do it, this article is about the first one.
The first option is using “user data”. The majority of clouds supports user data to pass information or scripts to be executed in the first boot of the instance. Terraform supports this too. One of the advantages of this approach is that it allows you to install the Salt Minion on instances without a public IP address.
In Terraform you pass the user data like this:
One of the problems is passing scripts to user data is the long strings, and there are two options to work around this...
The first one is using the file function:
resourceami user_data myscript sh
The second option is to use templates, which are more flexible if you need to pass some arguments to your script.
You need to define the template resource in Terraform first:resourceami user_data
resourcefilename vars roles environment
install_salt.sh https: bootstrap.saltstack.com install_salt.sh salt-master.flugel.it salt-call grains.setval roles salt-call grains.setval environment
Then when you run terraform apply, the template_file is going to be rendered with the values from template_file resource, before the instance is launched in the cloud.