Skip to content

Managing cloud instances with terraform

This page describes how to create new servers or cloud instances with various German IaaS hosting providers using terraform.

API tokens

Terraform requires an API token to manage instances with your cloud provider.


Create a new datacenter (Example name: cus_www_prod) in the hetzner cloud and go to Security -> API tokens to create a read & write token. Then add the API token in the playbook:

pass edit env_hcloud_cus_www_prod
source .env

Terraform provider Hetzner cloud documentation


IONOS cloud only wants your regular user and password to use terraform:

pass edit env_ionos_username
pass edit env_ionos_password
source .env

Terraform provider 1und1 IONOS cloud documentation


SysEleven uses OpenStack, which requires an API token:

pass edit env_os_auth_url
pass edit env_os_region_name
pass edit env_os_auth_token
source .env

All environment variables

Terraform provider Openstack documentation

Creating new servers

To manage a new group of servers with Ansible Cake, create the terraform configuration files below the terraform/ directory:

mkdir -p terraform/hcloud/cus_www_prod/
editor terraform/hcloud/cus_www_prod/

To take the config files of a similar project as a template:

cp -r terraform/hcloud/cus_util_prod terraform/hcloud/cus_www_prod
rm -rf terraform/hcloud/cus_www_prod/{.terraform,terraform.tfstate,terraform.tfstate.backup,}
editor terraform/hcloud/cus_www_prod/

To apply a new configuration:

# This might be required, if so the next step will also tell you that
terraform 0.13upgrade .

# Initialize terraform directory and install plugins
terraform init

# Dry-run
terraform plan

# Actually apply (will ask for your "yes" confirmation)
terraform apply

Adding to

To simplify the process of managing the new terraform setup for the next time, create a function like this in

# cus_www_prod
cus_www_prod_terraform() {
    cd terraform/cus_www_prod
    terraform init
    terraform apply
cus_www_prod_terraform_destroy() {
    cd terraform/cus_www_prod
    terraform destroy

This function can then be called with:

CAKE master * cake -f cus_www_prod_terraform

Modifying servers

If you later on want to change the servers and add RAM, CPUs or resize disks, simply edit the file and re-run cake -f cus_www_prod_terraform.