Getting started with Terraform in Glesys Cloud

By using Terraform you can automate your Glesys Cloud using code.


The Glesys Provider for Terraform lets you manage resources in Glesys Cloud. Currently, it supports, among other things, virtual machines (KVM and VMware), networking, load balancers, and object storage.

On GitHub, you can find our repository terraform-provider-glesys along with the accompanying documentation.

Prerequisites

You need permission to a Glesys Cloud account:

  • Open a free account here

  • A project in the control panel (this is where your services reside)

  • An API key. For this example, we use the following permissions for the Server module in the Glesys API:    

    • create

    • destroy

    • details

    • edit

    • list

Example

Here is an example where we create a virtual server and then increase its disk size.

You can use this configuration by creating a file named example.tf in a directory and then running the following commands from that directory:

  • Initialize a working directory for Terraform: terraform init

  • Generate and display an execution plan: terraform plan

  • Build your infrastructure: terraform apply

Step 1: Install and configure Terraform

For Terraform to communicate with the Glesys API, you need to provide a project ID (clXXXXX) from Glesys Cloud as the username and an API key that can authenticate against that project.

In this example, we’ll export environment variables in a shell so you don’t have to specify them each time a command interacts with the Glesys API.

Let's start by creating a directory for this example:

In the directory, create a file called example.tf, which is used when you download the GleSYS Provider. Give the file the following content.

By running the terraform init command, you initiate the download of the GleSYS Provider:

The output from the command will look similar to this:

You are now ready to create resources in Glesys Cloud!

Step 2: Create a virtual server

To create a virtual server, you need to add several parameters to the example.tf file. We recommend reading the documentation for glesys_server, where you can also see which parameters are required and which are optional.

If you want to spin up a virtual machine (KVM) running Debian 12 in the Stockholm data center and also create two users (alice and bob), the parameters would look like the example below. You can also clearly see how much resources have been allocated to the server. Add the following content to the previously created example.tf file:

To create the virtual machine, you first let Terraform read the configuration file and show which changes need to be made to your infrastructure. You do this by running terraform plan.

Then we run the terraform apply command to build the infrastructure:

After a successful run, you can move on to the next step.

Show the current state

With the terraform show command you can view the final result of the run. Details such as IPv4/IPv6 addresses have now been returned from the API.

Step 3: Increase the disk size

To increase the virtual machine’s disk size, simply modify the value in example.tf and run terraform apply again. In this example, we have changed it from 20 to 30 GiB.

Contribute open-source code

Everyone is welcome to contribute to the project with new features, improvements, and bug fixes. Read more about how to get started here.

Further reading

Last updated

Was this helpful?