Skip to content

Instantly share code, notes, and snippets.

@janeczku
Last active July 20, 2020 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janeczku/ca710baf4568073060732c40980e8d92 to your computer and use it in GitHub Desktop.
Save janeczku/ca710baf4568073060732c40980e8d92 to your computer and use it in GitHub Desktop.
Rancher Cluster from RKE Template TF

Fetch details of an existing RKE cluster template:

data "rancher2_cluster_template" "hardened" {
    name = "hardened-template"
}

or create a new RKE cluster template:

# Rancher cluster template 
resource "rancher2_cluster_template" "template_hardened" {
  name = "Hardened Cluster Template"
  template_revisions {
    name = "v1"
    default = true
    cluster_config {
      cluster_auth_endpoint {
        enabled = false
      }
      rke_config {
        kubernetes_version = "v1.15.12-rancher2-3"
        ignore_docker_version = false
        network {
          plugin = "flannel"
        }
        services { 
          etcd {
            backup_config {
              enabled = false
            }
          }
        }
      }
    }
    questions = [{
      default  = "v1.15.12-rancher2-3"
      required = false
      type     = string
      variable = "rancherKubernetesEngineConfig.kubernetesVersion"
    }]
}

Provision a new RKE Cluster from the template and specify variable overrides:

resource "rancher2_cluster" "foo" {
  name = "foo"
  cluster_template_id = "${data.rancher2_cluster_template.hardened.id}"
  cluster_template_revision_id = "${data.rancher2_cluster_template.hardened.default_revision_id}"
  cluster_template_answers {
    values = {
      "rancherKubernetesEngineConfig.kubernetesVersion" = "v1.15.12-rancher2-3"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment