How to create an RKE template and template revision using the Rancher2 Terraform Provider
This document (000020072) is provided subject to the disclaimer at the end of this document.
Situation
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
- Rancher RKE Template documentation .
- Rancher2 Terraform Provider
rancher2_cluster_template
resource documentation.
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.