Terraform/OpenTofu for Scaleway - Quickstart
Terraform and OpenTofu are Infrastructure as Code (IaC) software environment tools that allow you to easily build and maintain your cloud resources. You can use them to safely and efficiently deploy Scaleway resources in a declarative way.
Refer to the Scaleway Terraform or OpenTofu registry documentations for more information.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Initialized the Scaleway configuration file
- Installed Terraform or OpenTofu
Create and deploy Scaleway resources using Terraform/OpenTofu
This example guides you through the creation of a Kubernetes Kapsule cluster.
Create the Terraform/OpenTofu configuration file
-
Create a file named
main.tfin a new folder. -
Open the file in a code editor and paste the following block to define Scaleway as the provider for this deployment:
terraform { required_providers { scaleway = { source = "scaleway/scaleway" } } required_version = ">= 0.13" } -
Add the following block and replace the placeholder with the Project ID in which you want to create resources:
variable "project_id" { type = string description = "Project ID" default = "<YOUR_PROJECT_ID>" } -
Add the following blocks to fetch the latest available Kubernetes version, and create a Private Network, a Kubernetes cluster and its associated pool:
data "scaleway_k8s_version" "latest" { name = "latest" } resource "scaleway_vpc_private_network" "my-pn" { name = "my-private-network" } resource "scaleway_k8s_cluster" "my-cluster" { name = "my-cluster" type = "kapsule" version = data.scaleway_k8s_version.latest.name cni = "cilium" private_network_id = scaleway_vpc_private_network.my-pn.id delete_additional_resources = false } resource "scaleway_k8s_pool" "my-pool" { cluster_id = scaleway_k8s_cluster.my-cluster.id name = "my-pool" node_type = "DEV1-M" size = 1 min_size = 0 max_size = 1 autoscaling = true autohealing = true } -
Save your changes.
Your can now deploy your configuration on the Scaleway infrastructure.
Deploy your configuration using Terraform/OpenTofu
-
Open a terminal, access the folder you just created, and run the following command to initialize Terraform/OpenTofu in this folder:
-
Run the following command to display the actions that Terraform/OpenTofu will perform:
-
Review the deployment plan to make sure it matches the desired configuration.
-
Run the following command to deploy your resources:
Once the deployment is complete, log in to the Scaleway console to see the resources you have just created.
Delete Scaleway resources using Terraform/OpenTofu
-
Open a terminal, and access the folder containing the Terraform/OpenTofu configuration you want to delete.
-
Run the command below to delete the resources stated in the Terraform/OpenTofu configuration file:
A Destroy complete! Resources: X destroyed. message appears. Your Scaleway resources are now deleted.
Useful links
- Scaleway provider documentation on the Terraform Registry
- Scaleway provider documentation on the OpenTofu Registry
- Scaleway modules on Terraform/OpenTofu registry
- Terraform/OpenTofu provider Scaleway repository