Use Terraform with default variables to create Digital Ocean Droplets.
This repo contains terraform code and default variables that allow one to create Digital Ocean Droplet(s) with ease.
digitalocean_droplet
Terraform resource are enumerated in main.tf
and variables.tf
. tags
and volume_ids
are commented out for first-time ease.terraform apply
.Provisioners file
and remote-exec
are used to:
/etc/sysctl.conf
with a web-server optimized and kernel-hardened parameters.ssh_user
variable.admin
group./etc/sudoers
so that the admin
group can execute sudo
without a password.authorized_keys
file to ssh_user
’s .ssh
directory./etc/ssh/sshd_config
to disallow root
user login and allow PubkeyAuthentication
.write
.As long as these variables are provided, the defaults are to create one droplet in the sfo2
region with IPv6, monitoring, and private networking enabled.
do_token
: (string) Digital Ocean API Token.ssh_user
: (string) Name of user that will be allowed passwordless sudo and ssh access.ssh_key_path
: (string) path on local machine to SSH private key.vm_ssh_key_ids
: (list) ID(s) of SSH Key ID’s according to Digital Ocean. If providing over CLI, be wary of the data type. For example:var.vm_ssh_key_ids
Enter a value: [25435191]
Export your Digital Ocean API key:
export DIGITALOCEAN_TOKEN='YOUR_TOKEN_HERE'
Note: Piping to jq
required only for pretty-printing JSON response
terraform plan
terraform apply
export TF_LOG_='DEBUG' && \
export TF_LOG_PATH='tf.log'
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ${DIGITALOCEAN_TOKEN}" "https://api.digitalocean.com/v2/sizes?page=1" | jq
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ${DIGITALOCEAN_TOKEN}" "https://api.digitalocean.com/v2/sizes?page=2" | jq
Note: Multi-page responses
If you want SSH keys already associated with your Digital Ocean account to be set on the Droplets, you first need to get the ID(s) of the key(s) according to Digital Ocean.
curl -H "Content-Type: application/json" -H "Authorization: Bearer ${DIGITALOCEAN_TOKEN}" "https://api.digitalocean.com/v2/account/keys" | jq
vm_ssh_key_ids
variable.by: Andrew AadlandSeptember 17, 2018Visit site
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Have you created an Integration, API Wrapper, Service, or other Tool that helps developers build on DigitalOcean? Help users find it by listing it in Community Tools.