How to create an RKE template and template revision using the Rancher2 Terraform Provider

Follow
Table of Contents

Task

This article details how to create an RKE cluster template revision using the Rancher2 Terraform provider.

Pre-requisites

  • A Rancher v2.x instance, from v2.3.0 and above
  • Terraform and the Rancher2 Terraform Provider, authenticated with a Rancher user who has permission to create RKE Templates and RKE Template Revisions

Resolution

RKE cluster templates can be created using the Rancher2 Terraform Provider per the documentation on the rancher2_cluster_template resource.

An example of this resource can be found below:

resource "rancher2_cluster_template" "foo" {
  name = "foo"
  members {
    access_type = "owner"
    user_principal_id = "local://user-XXXXX"
  }
  template_revisions {
    name = "V1"
    cluster_config {
      rke_config {
        network {
          plugin = "canal"
        }
        services {
          etcd {
            creation = "6h"
            retention = "24h"
          }
        }
      }
    }
    default = true
  }
  description = "Terraform cluster template foo"
}

Having configured the Rancher2 Terraform Provider and added the above example resource, adjusting as desired and replacing local://user-XXXXX with a valid user prinical ID, run terraform apply to create the RKE template.

N.B. the default = true flag, which will specify this V1 revision as the the default revision.

To add additional revisions, each one will be nested as a new template_revisions block for that resource. Here is an example V2 revision:

template_revisions {
  name = "V2"
  cluster_config {
    rke_config {
      network {
        plugin = "canal"
      }
      services {
        etcd {
          creation = "3h"
          retention = "12h"
        }
      }
    }
  }
}

So, the full resource block would now look like this:

resource "rancher2_cluster_template" "foo" {
  name = "foo"
  members {
    access_type = "owner"
    user_principal_id = "local://user-XXXXX"
  }
  template_revisions {
    name = "V1"
    cluster_config {
      rke_config {
        network {
          plugin = "canal"
        }
        services {
          etcd {
            creation = "6h"
            retention = "24h"
          }
        }
      }
    }
    default = true

  }
  template_revisions {
    name = "V2"
    cluster_config {
      rke_config {
        network {
          plugin = "canal"
        }
        services {
          etcd {
            creation = "3h"
            retention = "12h"
          }
        }
      }
    }
  }
  description = "Terraform cluster template foo"
}

Run terraform apply and observe this second V2 revision created for the RKE template.

N.B. the default revision is still set to V1; this can be changed as needed.

Further reading

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.