Terraform module to create a Digital Ocean Droplet using the Terraform Salt Masterless Provisioner, including a tool
salt-push
which provides an easy way to push a new saltstack without needing to do a full system tear-down.
This module allows you to establish a Droplet on Digital Ocean with SaltStack in masterless mode easily as shown in the example below:-
variable "do_token" {} # set via environment value `TF_VAR_do_token`
provider "digitalocean" {
token = "${var.do_token}"
}
module "terraform-digitalocean-salt-masterless" {
source = "verbnetworks/salt-masterless/digitalocean"
# required variables
# ===
hostname = "node08"
digitalocean_region = "sgp1"
salt_local_state_tree = "/local/path/to/node08/states"
salt_local_pillar_roots = "/local/path/to/node08/pillars"
# optional variables
# ===
# digitalocean_volume0 = "<mount-point>:<mount-device>:<volume-id>:<mount-fstype>"
#
# Example:-
# digitalocean_volume0 = "/mnt:/dev/disk/by-id/scsi-0DO_Volume_example01:0010c05e-20ad-10e0-9007-00000c113408:ext4"
}
# optional outputs
output "hostname" { value = "${module.terraform-digitalocean-salt-masterless.hostname}" }
output "region" { value = "${module.terraform-digitalocean-salt-masterless.region}" }
output "ipv4_address" { value = "${module.terraform-digitalocean-salt-masterless.ipv4_address}" }
output "volume0" { value = "${module.terraform-digitalocean-salt-masterless.volume0}" }
output "salt_local_minion_config_file" { value = "${module.terraform-digitalocean-salt-masterless.salt_local_minion_config_file}" }
output "salt_local_state_tree" { value = "${module.terraform-digitalocean-salt-masterless.salt_local_state_tree}" }
output "salt_local_pillar_roots" { value = "${module.terraform-digitalocean-salt-masterless.salt_local_pillar_roots}" }
output "salt_remote_state_tree" { value = "${module.terraform-digitalocean-salt-masterless.salt_remote_state_tree}" }
output "salt_remote_pillar_roots" { value = "${module.terraform-digitalocean-salt-masterless.salt_remote_pillar_roots}" }
It is optionally possible to mount a pre-existing volume to your Droplet by providing the mount details in the
following format <mount-point>:<mount-device>:<volume-id>:<mount-fstype>
Obtaining the <volume-id>
value is not straight-forward through the Digital Ocean web admin user interface and
requires that you call their API to obtain it. You can consider using the digitalocean-api-query
cli tool with the "volumes" argument to discover this value.
$ digitalocean-api-query volumes | jq .volumes
[
{
"id": "0010c05e-20ad-10e0-9007-00000c113408",
"name": "example01",
"created_at": "2018-03-07T02:12:46Z",
...
An additional salt-push
tool is provided to easily push new salt-states and salt-pillars and invoke a remote
salt-call. The salt-push
tool achieves this by inspecting the (local) tfstate
file for information about the remote
system address, local and remote paths - this allows you to very easily push and update the remote saltstack with
a one-line command.
$ ./tools/salt-push /path/to/terraform.tfstate
salt-push
===
local_minion_config_file: /dev/null
local_states_path: /path/to/salt/states
local_pillars_path: /path/to/salt/pillars
remote_states_path: /srv/salt
remote_pillars_path: /srv/pillar
remote_address: x.x.x.x
connect to x.x.x.x on tcp:22 - Okay!
temp setting remote salt-config ownership to allow remote salt-config changes...
rsyncd remote_states_path - Okay!
rsyncd remote_pillars_path - Okay!
setting remote salt-config ownership back to root...
invoking salt-call over ssh...
...
Summary for local
------------
Succeeded: 4
Failed: 0
------------
Total states run: 4
Total run time: 70.244 ms
This module was originally published via https://github.com/ndejong/terraform-digitalocean-salt-masterless
and was subsequently moved which required it to be removed and re-added to the Terraform Module repository.
The hostname applied to this strelaysrv-node droplet.
The DigitalOcean region-slug to start this strelaysrv-node within (nyc1, sgp1, lon1, nyc3, ams3, fra1, tor1, sfo2, blr1)
Local path to the SaltStack state-tree to apply to the remote system
Local path to the SaltStack pillar-roots to apply to the remote system
Disable the root login after droplet has completed deployment - NB: the root bootstrap-sshkey remains in CLEARTEXT in the Terraform statefile, setting this parameter to '1' removes the bootstrap ssh-publickey from the remote system and sets PermitRootLogin to 'no' in the ssh-config after the bootstrap process is complete.
- default = 1
The salt-minion service is by default installed and started as a service which in a salt-headless arrangement is not required, this option by default disables that service.
- default = 1
Local salt minion config to be pushed to the remote system
- default = ""
Remote system remote_state_tree path
- default = "/srv/salt"
Remote system remote_pillar_roots path
- default = "/srv/pillar"
Salt custom_state definition
- default = ""
Salt logging level
- default = "warning"
The digitalocean image to use as the base for this digitalocean-droplet
- default = "ubuntu-18-04-x64"
The size to use for this digitalocean-droplet. default = "s-1vcpu-1gb"
Enable/disable backup functionality on this digitalocean-droplet.
- default = false
Enable/disable monitoring functionality on this digitalocean-droplet.
- default = true
Enable/disable getting a public IPv6 on this digitalocean-droplet.
- default = false
Enable/disable private-networking functionality on this digitalocean-droplet.
- default = false
List of tags to apply to this Droplet, the tags MUST already exist!
- default = []
Volume0 to attach to this digitalocean-droplet in the format <mount-point>:<mount-device>:<volume-id>:<mount-fstype>
- review README for information on discovering the value.
- default = ""
The hostname applied to this digitalocean-droplet.
The digitalocean region-slug this digitalocean-droplet is running in.
The public IPv4 address of this digitalocean-droplet.
The private IPv4 address of this digitalocean-droplet.
The public IPv6 address of this digitalocean-droplet.
The private IPv6 address of this digitalocean-droplet.
The volume attach to this digitalocean-droplet in the format <mount-point>:<mount-device>:<volume-id>:<mount-fstype>
The local SaltStack minion config file sent to the remote host
The local SaltStack state-tree path sent to the remote host
The local SaltStack pillar-root path sent to the remote host
The remote-system path to the SaltStack state-tree path
The remote-system path to the SaltStack pillar-roots path
Module managed by Verb Networks
Apache 2 Licensed. See LICENSE for full details.