Terraform Provider

Introduction

The IONOS provider for Terraform is used to interact with the cloud computing and storage resources provided by ProfitBricks. Before you begin you will need to have signed up for a IONOS account. The credentials you create during sign-up will be used to authenticate against the Cloud API.

Installation

Terraform must first be installed on your local machine or wherever you plan to run it from. Terraform is distributed as a binary package for various platforms and architectures.

To install Terraform, find the appropriate package for your system and download it. Terraform is packaged as a zip archive.

After downloading, unzip the package into a directory where Terraform will be installed. (Example: ~/terraform or c:\terraform)

The final installation step is to make sure the directory you installed Terraform into is included in the PATH.

If you plan to run terraform in a shell on Linux and placed the binary in /home/YOUR-USER-NAME/terraform/ then type the following into your terminal:

PATH=$PATH:/home/[YOUR-USER-NAME]/terraform

You can view the current value of $PATH by running:

echo $PATH

If you plan to run terraform in a shell on a Mac and placed the binary in /Users/YOUR-USER-NAME/terraform/ then type the following into your terminal:

PATH=$PATH:/Users/[YOUR-USER-NAME]/terraform

You can view the current value of $PATH by running:

echo $PATH

If you plan to run terraform.exe in PowerShell on Windows and placed the binary in c:\terraform then type the following into PowerShell:

First look at the existing value of PATH:

echo $env:Path

If it ends with a ;, then run:

$env:Path += "c:\terraform"

If it does NOT end with a ;, then run:

$env:Path += ";c:\terraform"

The adjustments to the PATH environment variable as outlined above are temporary. There are numerous examples available on the internet describing how to make permanent changes to environment variables for each particular operating system. The Terraform Installation instructions link to a couple examples.

If you do not want to mess around with changing the PATH at all, it is usually possible to execute items in a particular directory by entering ./terraform or providing a full path such as: c:\terraform\terraform.exe.

After installing Terraform, verify the installation by executing terraform or terraform.exe. You should see the default "usage" output similar to this:

$ terraform
usage: terraform [--version] [--help] <command> [<args>]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    push               Upload this Terraform module to Atlas to run
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    state              Advanced state management

ProfitBricks Provider

We now want to get the ProfitBricks provider installed. This is done easily by following these two steps:

First, add a section like this to your main.tf, or whatever .tf file you are using:

provider "profitbricks" {
}

Now run terraform init and the provider will be retrieved automatically.

You should see some output similar to:

# ./terraform init

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "profitbricks" (1.2.0)...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.profitbricks: version = "~> 1.2"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

If you happen to want to verify which providers are available to terraform, then pass it the providers option:

PS C:\Downloads\terraform_windows_amd64> .\terraform.exe providers
.
└── provider.profitbricks

In this case, the only provider currently installed is "profitbricks".

Configuration Reference

The following arguments are supported:

Parameter Required Type Description
username Yes string If omitted, the PROFITBRICKS_USERNAME environment variable is used. The username is generally an e-mail address in 'username@domain.tld' format.
password Yes string If omitted, the PROFITBRICKS_PASSWORD environment variable is used.
endpoint No string If omitted, the PROFITBRICKS_API_URL environment variable is used, or it defaults to the current Cloud API release. Only use this if you need to specifically override the version of the Cloud API that terraform will use.

This table summarizes deprecated arguments:

Parameter Required Type Description
retries No integer Number of retries while waiting for a resource to be provisioned. Default value is 50. Note: This argument has been deprecated and replaced by the implementation of resource timeouts described below.

Resource Timeouts

Individual resources may provide a timeouts block to configure the amount of time a specific operation is allowed to take before being considered an error. Each resource may provide configurable timeouts for the create, update, and delete operations. Each resource that supports timeouts will have or inherit default values for that operation. Users can overwrite the default values for a specific resource in the configuration.

The default timeouts values are all "60m":

Parameter Required Type Description
create No string Used for creating a resource.
update No string Used for updating a resource.
delete No string Used for destroying a resource.
default No string Used for other actions on a resource.

Valid units of time should be expressed in "s", "m", "h" for "seconds", "minutes", and "hours" respectively.

An example of overwriting the create, update, and delete timeouts:

resource "profitbricks_server" "example" {
  name              = "server"
  datacenter_id     = "${profitbricks_datacenter.example.id}"
  cores             = 1
  ram               = 1024
  availability_zone = "ZONE_1"
  cpu_family        = "AMD_OPTERON"

  volume {
    name           = "new"
    image_name     = "${var.ubuntu}"
    size           = 5
    disk_type      = "SSD"
    ssh_key_path   = "${var.private_key_path}"
    image_password = "test1234"
  }

  nic {
    lan             = "${profitbricks_lan.example.id}"
    dhcp            = true
    ip              = "${profitbricks_ipblock.example.ip}"
    firewall_active = true

    firewall {
      protocol         = "TCP"
      name             = "SSH"
      port_range_start = 22
      port_range_end   = 22
    }
  }

  timeouts {
    create = "30m"
    update = "300s"
    delete = "2h"
  }
}

Individual resources must opt-in to providing configurable timeouts, and attempting to configure values for a resource that does not support timeouts, or overwriting a specific action that the resource does not specify as an option, will result in an error.

Note: Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file will be partially updated with any resources that successfully completed.

Usage

We will go through a basic example of provisioning a server inside a Virtual Data Center after providing Terraform with our credentials.

Credentials

You can provide your credentials using the PROFITBRICKS_USERNAME and PROFITBRICKS_PASSWORD environment variables, representing your ProfitBricks username and password, respectively.

$ export PROFITBRICKS_USERNAME="profitbricks_username"
$ export PROFITBRICKS_PASSWORD="profitbricks_password"

Or you can include your credentials inside the main.tf file like this:

provider "profitbricks" {
    username = "profitbricks_username"
    password = "profitbricks_password"
}

Basic Example

In this example we will create a Virtual Data Center with an Ubuntu server:

First create a configuration directory:

mkdir ~/terraform

Change your current directory to the newly created directory:

cd ~/terraform

Create the text file main.tf. Terraform utilizes files with the extension .tf for configuration. Please Note: ALL files with the extension .tf WILL be parsed when running terraform, so don't use that extension for files that you don't want it to see.

In a Linux or Mac shell you might utilize vi, but any text editor should suffice.

vi main.tf

Copy following into main.tf:

// Credentials (unless you are using environment variables for these)
provider "profitbricks" {
  username = "profitbricks_username"
  password = "profitbricks_password"
}

//Virtual Data Center
resource "profitbricks_datacenter" "main" {
  name = "datacenter 01"
  location = "us/las"
  description = "Description of the Virtual Data Center"
}

//Public lan
resource "profitbricks_lan" "webserver_lan" {
  datacenter_id = "${profitbricks_datacenter.main.id}"
  public = true
  name = "public"
}

//IP Block
resource "profitbricks_ipblock" "webserver_ip" {
  location = "${profitbricks_datacenter.main.location}"
  size = 1
}

//Web server
resource "profitbricks_server" "webserver" {
  name = "webserver"
  datacenter_id = "${profitbricks_datacenter.main.id}"
  cores = 1
  ram = 1024
  availability_zone = "ZONE_1"
  cpu_family = "AMD_OPTERON"
  volume {
    name = "system"
    image_name = "${var.ubuntu}"
    size = 15
    disk_type = "HDD"
    ssh_key_path = "${var.private_key_path}"
    image_password = "test1234"
  }
  nic {
    lan = "${profitbricks_lan.webserver_lan.id}"
    dhcp = true
    ip = "${profitbricks_ipblock.webserver_ip.ips}"
    firewall_active = true
    firewall {
      protocol = "TCP"
      name = "SSH"
      port_range_start = 22
      port_range_end = 22
    }
  }
  provisioner "remote-exec" {
    inline = [
      # install nginx
      "apt-get update",
      "apt-get -y install nginx"
    ]
    connection {
      type = "ssh"
      private_key = "${file("${var.private_key_path}")}"
      user = "root"
      timeout = "4m"
    }
  }
}

Create the variables.tf text file and add these lines to specify Ubuntu 16.04 as the provisioned OS:

variable "ubuntu" {
  description = "Ubuntu Server"
  default = "ubuntu-16.04"
}

We are already setting a password of test1234 in the main.tf file, but we can pass a public SSH key to the build process by placing it in a file and including it in the configuration. This will add the public SSH key to the /root/.ssh/AUTHORIZED_KEYS file allowing us to connect using our private SSH key instead of a password. This will work with any of the Linux images provided by ProfitBricks. Once you have your public SSH key saved in /home/YOUR-USER-NAME/mypublicssh.key, then add these lines to variables.tf:

variable "private_key_path" {
  description = "Path to file containing private key"
  default = "/home/YOUR-USER-NAME/mypublicssh.key"
}

If you do not want to provide a public SSH key, then remove the line:

ssh_key_path = "${var.private_key_path}"

and remove the section that installs nginx:

provisioner "remote-exec" {
    inline = [
      # install nginx
      "apt-get update",
      "apt-get -y install nginx"
    ]
    connection {
      type = "ssh"
      private_key = "${file("${var.private_key_path}")}"
      user = "root"
      timeout = "4m"
    }
  }

from main.tf otherwise terraform plan will generate an error similar to this:

Error configuring: 2 error(s) occurred:

* profitbricks_server.webserver: missing dependency: var.private_key_path
* profitbricks_server.webserver: missing dependency: var.private_key_path

Now we run terraform with the plan parameter to review the execution plan:

$ terraform plan

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be persisted to local or remote state storage.


The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

+ profitbricks_datacenter.main
    description: "description of the datacenter"
    location:    "us/las"
    name:        "datacenter 01"

+ profitbricks_ipblock.webserver_ip
    ips:      "<computed>"
    location: "us/las"
    size:     "1"

+ profitbricks_lan.webserver_lan
    datacenter_id: "${profitbricks_datacenter.main.id}"
    name:          "public"
    public:        "true"

+ profitbricks_server.webserver
    availability_zone:                                   "ZONE_1"
    boot_cdrom:                                           "<computed>"
    boot_image:                                           "<computed>"
    boot_volume:                                          "<computed>"
    cores:                                               "1"
    cpu_family:                                          "AMD_OPTERON"
    datacenter_id:                                       "${profitbricks_datacenter.main.id}"
    name:                                                "webserver"
    nic.#:                                               "1"
    nic.~3990006432.dhcp:                                "true"
    nic.~3990006432.firewall.#:                          "1"
    nic.~3990006432.firewall.506939247.icmp_code:        ""
    nic.~3990006432.firewall.506939247.icmp_type:        ""
    nic.~3990006432.firewall.506939247.ip:               ""
    nic.~3990006432.firewall.506939247.name:             "SSH"
    nic.~3990006432.firewall.506939247.port_range_end:   "22"
    nic.~3990006432.firewall.506939247.port_range_start: "22"
    nic.~3990006432.firewall.506939247.protocol:         "TCP"
    nic.~3990006432.firewall.506939247.source_ip:        ""
    nic.~3990006432.firewall.506939247.source_mac:       ""
    nic.~3990006432.firewall.506939247.target_ip:        ""
    nic.~3990006432.firewall_active:                     "true"
    nic.~3990006432.ip:                                  "${profitbricks_ipblock.webserver_ip.ips}"
    nic.~3990006432.lan:                                 "0"
    nic.~3990006432.name:                                ""
    primary_nic:                                         "<computed>"
    ram:                                                 "1024"
    volume.#:                                            "1"
    volume.2973529261.bus:                               ""
    volume.2973529261.cpuHotPlug:                        "<computed>"
    volume.2973529261.cpuHotUnplug:                      "<computed>"
    volume.2973529261.discScsiHotPlug:                   "<computed>"
    volume.2973529261.discScsiHotUnplug:                 "<computed>"
    volume.2973529261.discVirtioHotPlug:                 "<computed>"
    volume.2973529261.discVirtioHotUnplug:               "<computed>"
    volume.2973529261.disk_type:                         "HDD"
    volume.2973529261.image_password:                    "test1234"
    volume.2973529261.licence_type:                      ""
    volume.2973529261.name:                              "system"
    volume.2973529261.nicHotPlug:                        "<computed>"
    volume.2973529261.nicHotUnplug:                      "<computed>"
    volume.2973529261.ramHotPlug:                        "<computed>"
    volume.2973529261.ramHotUnplug:                      "<computed>"
    volume.2973529261.size:                              "15"
    volume.2973529261.ssh_key_path:                      "/home/YOUR-USER-NAME/mypublicssh.key"

After you have reviewed the terraform plan output, proceed to build the infrastructure by running:

terraform apply

You should see output similar to this: (truncated)

profitbricks_datacenter.main: Creating...
  description: "" => "Description of the Virtual Data Center"
  location:    "" => "us/las"
  name:        "" => "datacenter 01"
profitbricks_datacenter.main: Creation complete
profitbricks_ipblock.webserver_ip: Creating...
  ips:      "" => "<computed>"
  location: "" => "us/las"
  size:     "" => "1"
profitbricks_lan.webserver_lan: Creating...
  datacenter_id: "" => "f40a859f-f110-41ad-9adf-49a42a25db91"
  name:          "" => "public"
  public:        "" => "true"
profitbricks_ipblock.webserver_ip: Creation complete
profitbricks_lan.webserver_lan: Still creating... (10s elapsed)
profitbricks_lan.webserver_lan: Creation complete
profitbricks_server.webserver: Creating...
  availability_zone:                                  "" => "ZONE_1"
  boot_cdrom:                                          "" => "<computed>"
  boot_image:                                          "" => "<computed>"
  boot_volume:                                         "" => "<computed>"
  cores:                                              "" => "1"
  cpu_family:                                         "" => "AMD_OPTERON"
  datacenter_id:                                      "" => "f40a859f-f110-41ad-9adf-49a42a25db91"
  name:                                               "" => "webserver"
  nic.#:                                              "0" => "1"
  nic.2035999756.dhcp:                                "" => "true"
  nic.2035999756.firewall.#:                          "0" => "1"
  nic.2035999756.firewall.506939247.icmp_code:        "" => ""
  nic.2035999756.firewall.506939247.icmp_type:        "" => ""
  nic.2035999756.firewall.506939247.ip:               "" => ""
  nic.2035999756.firewall.506939247.name:             "" => "SSH"
  nic.2035999756.firewall.506939247.port_range_end:   "" => "22"
  nic.2035999756.firewall.506939247.port_range_start: "" => "22"
  nic.2035999756.firewall.506939247.protocol:         "" => "TCP"
  nic.2035999756.firewall.506939247.source_ip:        "" => ""
  nic.2035999756.firewall.506939247.source_mac:       "" => ""
  nic.2035999756.firewall.506939247.target_ip:        "" => ""
  nic.2035999756.firewall_active:                     "" => "true"
  nic.2035999756.ip:                                  "" => "158.222.103.176"
  nic.2035999756.lan:                                 "" => "1"
  nic.2035999756.name:                                "" => ""
  primary_nic:                                        "" => "<computed>"
  ram:                                                "" => "1024"
  volume.#:                                           "0" => "1"
  volume.2973529261.bus:                              "" => ""
  volume.2973529261.cpuHotPlug:                       "" => "<computed>"
  volume.2973529261.cpuHotUnplug:                     "" => "<computed>"
  volume.2973529261.discScsiHotPlug:                  "" => "<computed>"
  volume.2973529261.discScsiHotUnplug:                "" => "<computed>"
  volume.2973529261.discVirtioHotPlug:                "" => "<computed>"
  volume.2973529261.discVirtioHotUnplug:              "" => "<computed>"
  volume.2973529261.disk_type:                        "" => "HDD"
  volume.2973529261.image_password:                   "" => "test1234"
  volume.2973529261.licence_type:                     "" => ""
  volume.2973529261.name:                             "" => "system"
  volume.2973529261.nicHotPlug:                       "" => "<computed>"
  volume.2973529261.nicHotUnplug:                     "" => "<computed>"
  volume.2973529261.ramHotPlug:                       "" => "<computed>"
  volume.2973529261.ramHotUnplug:                     "" => "<computed>"
  volume.2973529261.size:                             "" => "15"
  volume.2973529261.ssh_key_path:                     "" => "/home/YOUR-USER-NAME/mypublicssh.key"
  ...
  ...
  Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

If you happen to get stuck, and Terraform is not working as you expect, you can start over by deleting the terraform.tfstate file, and manually destroying any resources that were provisioned. This can be done quickly using the ProfitBricks Data Center Designer (DCD) or by making calls to the Cloud API using curl or another tool for interacting with a REST-based API.

If you want to see more information in the log, you can set the TF_LOG environment variable. From a shell on Linux, this can be done using export:

export TF_LOG=1

If you wish to update one of the resources in the main.tf, just edit main.tf and make changes to the specific resource. For example, to rename the Virtual Data Center:

//Virtual Data Center
resource "profitbricks_datacenter" "main" {
  name = "datacenterrename"
  location = "us/las"
  description = "Description of the Virtual Data Center"
}
...

After you are done with editing run this:

 terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be persisted to local or remote state storage.

profitbricks_datacenter.main: Refreshing state... (ID: f40a859f-f110-41ad-9adf-49a42a25db91)
profitbricks_ipblock.webserver_ip: Refreshing state... (ID: 7d0746c7-7985-4050-8770-5c39197e179d)
profitbricks_lan.webserver_lan: Refreshing state... (ID: 1)
profitbricks_server.webserver: Refreshing state... (ID: 82100380-3ecb-4bfd-9cd7-01bd4f2d8127)

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

~ profitbricks_datacenter.main
    name: "datacenter 01" => "datacenterrename"

Terraform will inform you about the changes that will happen once you run terraform apply. If you are satisfied with the summarized changes, then run terraform apply.

To remove the infrastructure you used Terraform to create, run:

$ terraform destroy

Do you really want to destroy?
  Terraform will delete all your managed infrastructure.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value:

This will remove the entire infrastructure defined in main.tf.

Additional information about the Terraform CLI is available.

Resource Reference

This section describes the various ProfitBricks resource types that can be deployed using this Terraform provider.

Virtual Data Center

Example Syntax

resource "profitbricks_datacenter" "example" {
  name = "datacenter name"
  location = "us/las"
  description = "Virtual Data Center description"
}

Argument Reference

The following arguments are supported:

Parameter Required Type Description
name Yes string The name of the Virtual Data Center.
location Yes string The physical location where the Virtual Data Center will be created. ["us/las", "us/ewr", "de/fra", or "de/fkb"]
description No string A description of the Virtual Data Center.

Server

This resource will create an operational server. After this section completes, the provisioner can be called.

Example Syntax

resource "profitbricks_server" "example" {
     name = "server"
     datacenter_id = "${profitbricks_datacenter.example.id}"
     cores = 1
     ram = 1024
     availability_zone = "ZONE_1"
     cpu_family = "AMD_OPTERON"

     volume {
       name = "new"
       image_name = "${var.ubuntu}"
       size = 15
       disk_type = "SSD"
       ssh_key_path = "${var.private_key_path}"
       image_password = "test1234"
     }

     nic {
       lan = "${profitbricks_lan.example.id}"
       dhcp = true
       ip = "${profitbricks_ipblock.example.ip}"
       firewall_active = true

       firewall {
         protocol = "TCP"
         name = "SSH"
         port_range_start = 22
         port_range_end = 22
       }
     }
}

Argument Reference

Parameter Required Type Description
name Yes string The name of the server.
datacenter_id Yes* string The UUID of the Virtual Data Center the server resource is associated with.
cores Yes integer The number of processor cores assigned to this server.
ram Yes integer The amount of memory assigned to this server in MB.
availability_zone No string The compute resource availability zone. ["AUTO", "ZONE_1", or "ZONE_2"]
cpu_family No string Sets the CPU type. ["AMD_OPTERON" or "INTEL_XEON"]
volume Yes See Volume section.
nic Yes See NIC section.
firewall No See Firewall Rule section.
boot_volume Computed The associated boot volume.
boot_cdrom Computed The associated boot drive, if any.
boot_image Computed The associated boot image.
primary_nic Computed The associated NIC.
primary_ip Computed The associated IP address.

* See the Description column for details.

Volume

A primary volume will be created with the server. If there is a need for additional volumes, this resource handles it.

Example Syntax

resource "profitbricks_volume" "example" {
  datacenter_id = "${profitbricks_datacenter.example.id}"
  server_id = "${profitbricks_server.example.id}"
  image_name = "${var.ubuntu}"
  size = 5
  disk_type = "HDD"
  sshkey_path = "${var.private_key_path}"
  bus = "VIRTIO"
}

Argument Reference

Parameter Required Type Description
datacenter_id Yes* string UUID of an existing Virtual Data Center resource. This parameter is not required if used under Server resource.
server_id Yes* string UUID of an existing server resource. This parameter is not required if used under Server resource.
disk_type Yes string The storage volume type. ["HDD", or "SSD"]
bus Yes string The bus type of the storage volume. ["VIRTIO", or "IDE"]
size Yes integer The size of the storage volume in GB.
image_password Yes* string Password set for the root or Administrator user on ProfitBricks provided images. Required if ssh_key_path is not provided.
ssh_key_path Yes* string Path to a file containing a public SSH key that will be injected into ProfitBricks provided Linux images. Required for ProfitBricks Linux images. Required if image_password is not provided.
sshkey Computed The associated public SSH key.
image_name Yes* string The image or snapshot UUID. May also be an image alias. It is required if licence_type is not provided.
licence_type Yes* string Required if image_name is not provided. ["LINUX", "WINDOWS", "WINDOWS2016", or "OTHER"]
name No string A name for the storage volume.
availability_zone No string The storage availability zone assigned to the volume. ["AUTO", "ZONE_1", "ZONE_2", "ZONE_."]

* See the Description column for details.

Snapshot

Example Syntax

resource "profitbricks_snapshot" "test_snapshot" {
  datacenter_id = "datacenterId"
  volume_id = "volumeId"
  name = "my snapshot"
}

Argument Reference

Parameter Required Type Description
datacenter_id Yes* string UUID of an existing Virtual Data Center resource.
volume_id Yes string The ID of the specific volume to take a snapshot of.
name Yes string A name for the snapshot.

NIC

Example Syntax

resource "profitbricks_nic" "example" {
  datacenter_id = "${profitbricks_datacenter.example.id}"
  server_id = "${profitbricks_server.example.id}"
  lan = 2
  dhcp = true
  ip = "${profitbricks_ipblock.example.ip}"
}

Argument Reference

Parameter Required Type Description
datacenter_id Yes* string UUID of an existing Virtual Data Center resource. This parameters is not required if used under Server resource.
server_id Yes* string UUID of an existing server resource. This parameters is not required if used under Server resource.
lan Yes integer The LAN ID the NIC will sit on.
name No string The name of the LAN.
dhcp No Boolean If the NIC should get an IP using DHCP.
ip No string IP assigned to the NIC.
firewall_active No Boolean If this resource is set to true and is nested under a server resource firewall, with open SSH port, resource must be nested under the NIC.
nat No Boolean Value "true" indicating that the private IP address has outbound access to the public internet. Not currently implemented.
ips Computed The IP address or addresses assigned to the NIC.

* See the Description column for details.

IP Block

Example Syntax

resource "profitbricks_ipblock" "example" {
  location = "${profitbricks_datacenter.example.location}"
  size = 1
}

Argument Reference

Parameter Required Type Description
location Yes string The physical location where the Virtual Data Center will be created. ["us/las", "us/ewr", "de/fra", or "de/fkb"]
size Yes integer The number of IP addresses reserved in the IP Block.
ips Computed IP addresses associated with this IP Block.

LAN

Example Syntax

resource "profitbricks_lan" "example" {
  datacenter_id = "${profitbricks_datacenter.example.id}"
  public = true
}

Argument Reference

Parameter Required Type Description
datacenter_id Yes* string UUID of an existing Virtual Data Center resource. This parameters is not required if used under Server resource.
name No string The name of the LAN
public No Boolean Indicates if the LAN faces the public Internet or is "private".

* See the Description column for details.

Firewall Rule

Example Syntax

resource "profitbricks_firewall" "example" {
  datacenter_id = "${profitbricks_datacenter.example.id}"
  server_id = "${profitbricks_server.example.id}"
  nic_id = "${profitbricks_server.example.primary_nic}"
  protocol = "TCP"
  name = "test"
  port_range_start = 1
  port_range_end = 2
}

Argument Reference

Parameter Required Type Description
datacenter_id Yes* string UUID of an existing Virtual Data Center resource. This parameter is not required if used under Server resource.
server_id Yes* string UUID of an existing server resource. This parameter is not required if used under Server resource.
nic_id Yes* string UUID of an existing server resource. This parameter is not required if used under Server resource.
protocol Yes string The protocol for the rule: ["TCP", "UDP", "ICMP", "ANY"]
name No string The name of the firewall rule.
source_mac No string Only traffic originating from the respective MAC address is allowed. Valid format: aa:bb:cc:dd:ee:ff.
source_ip No string Only traffic originating from the respective IPv4 address is allowed.
target_ip No string Only traffic directed to the respective IP address of the NIC is allowed.
port_range_start No string Defines the start range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen.
port_range_end No string Defines the end range of the allowed port (from 1 to 65534) if the protocol TCP or UDP is chosen.
icmp_type No string Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen.
icmp_code No string Defines the allowed code (from 0 to 254) if protocol ICMP is chosen.

* See the Description column for details.

Load Balancer

Example Syntax

resource "profitbricks_loadbalancer" "example" {
  datacenter_id = "${profitbricks_datacenter.example.id}"
  nic_ids = "${profitbricks_nic.example.id}"
  name = "load balancer name"
  dhcp = true
}

Argument Reference

Parameter Required Type Description
name Yes string The name of the load balancer.
datacenter_id Yes* string UUID of an existing Virtual Data Center resource. This parameter is not required if used under Server resource.
nic_ids Yes* list List of NICs that are part of the load balancer.
dhcp No Boolean Indicates if the load balancer will reserve an IP using DHCP.
ip No string IPv4 address of the load balancer.

* See the Description column for details.

IP Failover

Example Syntax

resource "profitbricks_ipfailover" "failovertest" {
  datacenter_id = "datacenterId"
  lan_id="lanId"
  ip ="reserved IP"
  nicuuid= "nicId"
}

Arugment Reference

Parameter Required Type Description
datacenter_id Yes* string UUID of an existing Virtual Data Center resource.
ip Yes string The reserved IP address to be used in the failover group.
lan_id Yes string The ID of a LAN.
nicuuid Yes string The ID of a NIC.

User

Manages users and list users and groups associated.

Example Usage

resource "profitbricks_user" "user" {
  first_name = "terraform"
  last_name = "test"
  email = "user@domain.tld"
  password = "abc123-321CBA"
  administrator = false
  force_sec_auth= false
}

Argument Reference

Parameter Required Type Description
administrator Yes Boolean The group has permission to edit privileges on this resource.
email Yes string An e-mail address for the user.
first_name Yes string A name for the user.
force_sec_auth Yes Boolean The group has permission to user this resource.
last_name Yes string A name for the user.
password Yes string A password for the user.

Group

Manages groups and group privileges on ProfitBricks

Example Usage

resource "profitbricks_group" "group" {
  name = "my group"
  create_datacenter = true
  create_snapshot = true
  reserve_ip = true
  access_activity_log = false
  user_id="user_id"
}

Argument Reference

Parameter Required Type Description
access_activity_log Yes Boolean The group will be allowed to access the activity log.
create_datacenter No Boolean The group will be allowed to create Virtual Data Centers.
create_snapshot No Boolean The group will be allowed to create snapshots.
name No string A name for the group.
reserve_ip No Boolean The group will be allowed to reserve IP addresses.
user_id No string The ID of the specific user to add to the group.

Share

Manages shares and list shares permissions granted to the group members for each shared resource.

Example Usage

resource "profitbricks_share" "share" {
  group_id = "groupId"
  resource_id = "resourceId"
  edit_privilege = true
  share_privilege = false
}

Argument Reference

Parameter Required Type Description
edit_privilege Yes Boolean The group has permission to edit privileges on this resource.
group_id Yes string The ID of the specific group containing the resource to update.
resource_id Yes string The ID of the specific resource to update.
share_privilege Yes Boolean The group has permission to share this resource.

Data Source Reference

Data Centers

The profitbricks_datacenter data source can be used to search for and return an existing Virtual Data Center. You can provide a string for the name and location parameters which will be compared with provisioned Virtual Data Centers. If a single match is found, it will be returned. If your search results in multiple matches, an error will be generated. When this happens, please refine your search string so that it is specific enough to return only one result.

Example Usage

data "profitbricks_datacenter" "dc_example" {
  name     = "test_dc"
  location = "us"
}

Argument Reference

Parameter Required Type Description
name Yes string Name or part of the name of an existing Virtual Data Center that you want to search for.
location No string ID of the existing Virtual Data Center's location.

Attributes Reference

Parameter Description
id UUID of the Virtual Data Center.

Images

The profitbricks_image data source can be used to search for and return an existing image which can then be used to provision a server.

Example Usage

data "profitbricks_image" "image_example" {
  name     = "Ubuntu"
  type     = "HDD"
  version  = "14"
  location = "location_id"
}

Argument Reference

Parameter Required Type Description
name Yes string Name or part of the name of an existing image that you want to search for.
version No string Version of the image (see details below).
location No string ID of the existing image's location.
type No string The image type. ["HDD" or "CD-ROM"]

If both name and version are provided the plugin will concatenate the two strings in this format "[name]-[version]".

Attributes Reference

Parameter Description
id UUID of the matching image.

Locations

The profitbricks_location data source can be used to search for and return an existing location which can then be used elsewhere in the configuration.

Example Usage

data "profitbricks_location" "loc1" {
  name    = "karlsruhe"
  feature = "SSD"
}

Argument Reference

Parameter Required Type Description
name Yes string Name or part of the location name to search for.
feature No string A desired feature that the location must be able to provide.

Attributes Reference

Parameter Description
id UUID of the matching location.

Resources

The profitbricks_resource data source can be used to search for and return any existing ProfitBricks resource and optionally their group associations. You can provide a string for the resource type (datacenter, image, snapshot, ipblock) and/or resource ID parameters which will be queried against available resources. If a single match is found, it will be returned. If your search results in multiple matches, an error will be generated. When this happens, please refine your search string so that it is specific enough to return only one result.

Example Usage

data "profitbricks_resource" "res" {
  resource_type = "datacenter"
  resource_id="datacenter uuid"
}

Argument Reference

Parameter Required Type Description
resource_type No string The specific type of resources to retrieve information about.
resource_id No string The ID of the specific resource to retrieve information about.

Attributes Reference

Parameter Description
id UUID of the matching resource.

Snapshots

The profitbricks_snapshot data source can be used to search for and return an existing snapshot which can then be used to provision a server.

Example Usage

data "profitbricks_snapshot" "snapshot_example" {
  name     = "my snapshot"
  size     = "2"
  location = "location_id"
}

Argument Reference

Parameter Required Type Description
name Yes string Name or part of the name of an existing snapshot that you want to search for.
location No string ID of the existing snapshot location.
size No string The size of the snapshot to look for.

Attributes Reference

Parameter Description
id UUID of the matching snapshot.

Support

You are welcome to contact us with questions or comments at IONOS DevOps Central. Please report any issues via GitHub's issue tracker.