Managing cloud infrastructure can be a complex task, especially when you’re working with multiple providers or regions. Terraform, a leading Infrastructure as Code (IaC) tool, simplifies this by enabling users to provision and manage their infrastructure using declarative configuration files. Leaseweb has just released a new Terraform provider, giving you the ability to manage both dedicated servers and public cloud instances—putting a particular focus on public cloud infrastructure.
In this post, we’ll guide you through using the latest iteration of the Leaseweb Terraform provider to manage your public cloud instances. We’ll cover how to install the provider, configure it, and dive into some practical examples, including handling multiple sales organizations with distinct data hosting regions.
What’s New with the Leaseweb Terraform Provider
While the Leaseweb Terraform provider previously allowed users to provision dedicated servers, the new features for managing Leaseweb Public Cloud instances open up a world of possibilities for managing scalable, on-demand compute resources.
Key new features of the Leaseweb Terraform provider include:
- Provisioning Public Cloud Instances: You can now manage public cloud instances in multiple regions with ease.
- Billing Flexibility: Configure hourly billing or longer-term contracts based on your needs.
- Regional and Contract Separation: Manage resources across different regions, including specific country-level data centers, while maintaining legal separation via the use of multiple sales organizations.
How to Install and Set Up the Leaseweb Terraform Provider
1. How to Obtain Your API Token
To authenticate your Terraform configuration, you need an API token from Leaseweb. Here’s how you can generate one:
- Log in to your Leaseweb Customer Portal.
- Navigate to the API Key section under Administration.
- Follow the instructions to create a new API key.
- Copy the generated token and use it in your Terraform configuration under the token field.
Once you have your API token, you can use it to authenticate with Leaseweb’s platform and manage your resources via Terraform.
2. Installation
To get started, ensure you’re using Terraform 1.x or later. Then, define the Leaseweb provider in your Terraform configuration file (main.tf). Here’s how you can install and configure the provider:
terraform { required_providers { leaseweb = { version = “1.8.0-beta” source = “leaseweb/leaseweb” } } } provider “leaseweb” { token = “super-secret-token-value” }
In this configuration:
- Token: You’ll need to replace “super-secret-token-value” with your actual API token from Leaseweb.
- Version: The example uses the 1.8.0-beta version of the provider, so ensure you have the correct version installed.
3. Managing Public Cloud Instances
Now let’s dive into how to provision a public cloud instance using Terraform. Below is an example of how you can create a public cloud instance within the Leaseweb platform:
# Manage example Public Cloud Instance resource “leaseweb_public_cloud_instance” “example” { contract = { billing_frequency = 1 term = 0 type = “HOURLY” } image = { id = “UBUNTU_22_04_64BIT” } reference = “my webserver” region = “eu-west-3” root_disk_storage_type = “CENTRAL” type = “lsw.m3.large” }
In this configuration:
- contract: Defines the billing frequency (e.g., hourly).
- image: Specifies the OS image (e.g., Ubuntu 22.04).
- region: Set to eu-west-3 (which represents a specific Leaseweb data center region).
- root_disk_storage_type: Defines the storage type (e.g., CENTRAL for standard storage).
- type: Specifies the instance type (e.g., lsw.m3.large).
This configuration is a basic example, but you can expand upon it by adding additional parameters like tags, SSH keys, and more based on your needs.
4. Working with Multiple Sales Organizations
One of the unique features of Leaseweb is its work with multiple sales organizations, each providing legal separation for data hosting in different geographic regions. You can define separate providers for different sales organizations and easily manage resources in distinct regions.
Here’s how you can define multiple providers for different regions (e.g., Germany and Canada) and manage cloud instances in those regions:
h terraform { required_providers { leaseweb = { version = “1.8.0-beta” source = “leaseweb/leaseweb” } } } provider “leaseweb” { alias = “germany” token = “random-token-from-germany” } provider “leaseweb” { alias = “canada” token = “random-token-from-canada” } resource “leaseweb_public_cloud_instance” “example-germany” { provider = leaseweb.germany contract = { billing_frequency = 1 term = 0 type = “HOURLY” } image = { id = “UBUNTU_22_04_64BIT” } reference = “my webserver” region = { name = “eu-west-3” } root_disk_storage_type = “CENTRAL” type = { name = “lsw.m3.large” } } resource “leaseweb_public_cloud_instance” “example-canada” { provider = leaseweb.canada contract = { billing_frequency = 1 term = 0 type = “HOURLY” } image = { id = “UBUNTU_22_04_64BIT” } reference = “my webserver” region = { name = “ca-central-1” } root_disk_storage_type = “CENTRAL” type = { name = “lsw.m3.large” } }
With the new Leaseweb Terraform provider, managing both dedicated servers and public cloud instances has never been easier. This integration allows you to seamlessly provision and configure cloud resources, while also offering flexibility with billing options and region-based data separation. By using Terraform’s declarative configuration and automation capabilities, you can scale your infrastructure while maintaining full control.
As cloud infrastructure continues to grow and diversify, tools like Terraform and providers like Leaseweb will be instrumental in helping you manage your resources efficiently and securely. Whether you’re a long-time Leaseweb customer or exploring the platform for the first time, this new functionality is a game-changer for automating and managing your cloud environments.
Ready to automate your cloud infrastructure with Terraform? Get started today by setting up your Leaseweb Terraform provider and take your infrastructure management to the next level!