If you do not specify a Project ID, Terraform will use the default Project specified in the Scaleway configuration file.
Terraform for Scaleway - Quickstart
Terraform is an Infrastructure as Code (IaC) software environment tool that allows you to easily build and maintain your cloud resources. You can use it to safely and efficiently deploy Scaleway resources in a declarative way.
Check out the Scaleway Terraform registry documentation 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
Creating and Deploying Scaleway resources using Terraform
For the sake of this example, we are going to create a Kubernetes Kapsule cluster.
Creating the Terraform configuration file
-
Create a new file called
main.tf
in 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 = stringdescription = "<PROJECT_ID>"}Note -
Add the following blocks to create a Private Network, a Kubernetes cluster and its associated pool:
resource "scaleway_vpc_private_network" "my-pn" {name = "my-private-network"}resource "scaleway_k8s_cluster" "my-cluster" {name = "my-cluster"type = "kapsule"version = "1.28.2"cni = "cilium"private_network_id = scaleway_vpc_private_network.my-pn.iddelete_additional_resources = false}resource "scaleway_k8s_pool" "my-pool" {cluster_id = scaleway_k8s_cluster.my-cluster.idname = "my-pool"node_type = "DEV1-M"size = 1min_size = 0max_size = 1autoscaling = trueautohealing = true}NoteRefer to the Scaleway provider documentation on the Terraform Registry to learn how to deploy other resources.
-
Save your changes.
Your configuration is now ready to be deployed on Scaleway’s infrastructure.
Deploying your configuration using Terraform
- Open a terminal, access the folder you just created, and run the following command to initialize Terraform in this folder:
terraform init
- Run the following command to display the actions that Terraform will perform:
terraform plan
- Review the deployment plan to make sure it matches the desired configuration.
- Run the following command to deploy your resources:
terraform apply
Once the deployment is complete, log in to the Scaleway console to see the resources you have just created.
Deleting Scaleway resources using Terraform
-
Open a terminal and access the folder containing the Terraform configuration you want to delete.
-
Run the command below to delete the resources stated in the Terraform configuration file:
terraform destroyImportantYou can only delete resources created with Terraform and described in the configuration file.
A Destroy complete! Resources: X destroyed.
message appears, your Scaleway resources are now deleted.