# On Scaleway

> Deploy a Kubernetes cluster for Mélodium runners on Scaleway with the Terraform module.

Web page: https://docs.cadence.ci/en/clusters/scaleway

Mélodium provides an all-in-one Terraform module to deploy clusters on [Scaleway](https://www.scaleway.com/):  
[`scaleway-kubernetes-cluster`](https://registry.terraform.io/modules/melodium-tech/scaleway-kubernetes-cluster/melodium).

> [!NOTE]
>
> You need Terraform to be installed first to follow those steps, take a look at [Terraform.io](https://www.terraform.io/) if you don't have it yet.

## Authenticate with Scaleway

To run the Scaleway Terraform Provider, `SCW_ACCESS_KEY` and `SCW_SECRET_KEY` environment variables must be set up.  
Refer to the [Authentication](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs#authentication) section of Scaleway Terraform Provider to proceed.

## Authenticate with Cluster Token

In your account, go to _Tokens_ > _Cluster Tokens_ and _New Token_ to generate a new token usable for clusters.

## Create Terraform Configuration

Create a new directory and write into a file named `main.tf` the following content:
```terraform

module "scaleway-kubernetes-cluster" {
  source  = "melodium-tech/scaleway-kubernetes-cluster/melodium"
  version = "0.0.3"
  
  // Project UUID (available in Scaleway Console near project name)
  project_id = "<YOUR PROJECT ID>" 
  
  cluster_name = "beautiful-test-cluster"
  cluster_description = "Cluster test on Scaleway"
  cluster_token = "<YOUR CLUSTER TOKEN>"

  /*
  Other available variables:

  region = "fr-par"
  zone = "fr-par-2"
  cluster_work_pools = {
    "arm-4C-16G" = {
      node_type = "COPARM1-4C-16G" // Scaleway Node Type
      volume_size = 80 // Disk in GB
      min_size = 0 // Minimal number of machines present at any time in this pool
      max_size = 4 // Absolute maximum number of machines in this pool
    },
    "amd-4C-16G" = {
      node_type = "GP1-XS"
      volume_size = 80
      min_size = 0
      max_size = 4
    }
  }
  */
  
}

```

## Run Terraform

Run the following commands in a terminal within the folder containing `main.tf`:

```sh
terraform init
terraform apply
```

Once operation is complete, your new cluster is ready and your Mélodium distributed jobs will be sent to it.

## Delete the cluster

Once you want to delete the cluster, run:
```sh
terraform destroy
```
This will remove all the resources associated with the cluster, and disable it on the Mélodium Distribution API.
