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

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.

  • Document ID:000020072
  • Creation Date: 06-May-2021
  • Modified Date:06-May-2021
    • SUSE Rancher

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback@suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center