Skip to content

How to upgrade a Rancher-managed k3s cluster via the Rancher2 Terraform Provider

Article Number: 000020698

Situation

How to use the Rancher2 Terraform Provider to update an existing downstream cluster managed by Rancher.

Resolution

To do this import the k3s cluster into the Terraform configuration, then upgrade the cluster via Terraform. 

Firstly, with the Rancher2 Terraform Provider configured (https://registry.terraform.io/providers/rancher/rancher2/latest/docs), define a rancher2_cluster resource for your k3s cluster, per the following example:

resource "rancher2_cluster" "k3s" {
    name = "k3s"
}

Then use the `terraform import` command to import the k3s cluster into your Terraform configuration (https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster#import), e.g.:

terraform import rancher2_cluster.k3s c-m-h6xkkkvs

Finally with the cluster imported, set the Kubernetes version in the k3s_config block to upgrade the cluster via a `terraform apply` operation, e.g.:

resource "rancher2_cluster" "k3s" {
    name = "k3s"
    k3s_config {
        version = "v1.23.7+k3s1"
    }
}