Skip to content

Instantly share code, notes, and snippets.

@yankcrime
Created April 16, 2021 07:35
Show Gist options
  • Save yankcrime/7fd39df1211236c317a154d4930fa997 to your computer and use it in GitHub Desktop.
Save yankcrime/7fd39df1211236c317a154d4930fa997 to your computer and use it in GitHub Desktop.
Provisioning a 'RKE' downstream cluster on existing nodes via Terraform
resource "rancher2_cluster" "downstream_cluster" {
name = var.cluster_name
description = var.cluster_description
rke_config {
kubernetes_version = var.kubernetes_version
services {
kube_api {
secrets_encryption_config {
enabled = true
}
}
}
}
}
resource "null_resource" "downstream_cluster_deploy" {
for_each = var.cluster_nodes
provisioner "remote-exec" {
inline = ["${rancher2_cluster.downstream_cluster.cluster_registration_token.0["node_command"]} ${each.value}"]
connection {
host = each.key
user = var.ssh_user
type = "ssh"
script_path = "~${var.ssh_user}/rke.sh"
}
}
depends_on = [rancher2_cluster.downstream_cluster]
}
provider "rancher2" {
api_url = "https://${var.rancher_hostname}/v3"
access_key = var.rancher_access_key
secret_key = var.rancher_secret_key
insecure = true
}
rancher_hostname = "rancher.192.168.1.210.dnsify.me"
rancher_access_key = "token-b92bf"
rancher_secret_key = "c84w6lldqmccdw6qcws8rs2k2w9w7kwlvmjl86s92tkdrh2tz9pg8v"
ssh_user = "nick"
variable "rancher_hostname" {
description = "URL to the Rancher API"
default = ""
}
variable "rancher_access_key" {
description = "API access key for Rancher"
default = ""
}
variable "rancher_secret_key" {
description = "API secret key for Rancher"
default = ""
}
variable "kubernetes_version" {
description = "Version of Kubernetes to deploy"
default = "v1.19.3-rancher1-2"
}
variable "ssh_user" {
description = "Username for SSH access to VMs"
default = "ubuntu"
}
variable "cluster_name" {
default = "demo"
description = "Name of cluster"
}
variable "cluster_description" {
default = "Demo cluster"
description = "Description of purpose of cluster"
}
variable "cluster_nodes" {
type = map(string)
default = {
"192.168.1.11" = "--controlplane --etcd"
"192.168.1.12" = "--worker"
}
}
terraform {
required_providers {
null = {
source = "hashicorp/null"
}
rancher2 = {
source = "rancher/rancher2"
}
}
required_version = ">= 0.13"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment