Skip to content

Instantly share code, notes, and snippets.

@swade1987
Created December 28, 2017 18:43
Show Gist options
  • Save swade1987/3dbaa69307b48217658c478ff952d0be to your computer and use it in GitHub Desktop.
Save swade1987/3dbaa69307b48217658c478ff952d0be to your computer and use it in GitHub Desktop.
# Interpolate the generate values
data "template_file" "kismatic_cluster" {
template = "${file("${path.module}/user-data/kismatic-cluster.yaml.tpl")}"
vars {
etcd1_ip = "${digitalocean_droplet.etcd_nodes.0.ipv4_address}"
master_loadbalancer_ip = "${digitalocean_loadbalancer.master_lb.ip}"
master1_ip = "${digitalocean_droplet.master_nodes.0.ipv4_address}"
master2_ip = "${digitalocean_droplet.master_nodes.1.ipv4_address}"
worker1_ip = "${digitalocean_droplet.worker_nodes.0.ipv4_address}"
worker2_ip = "${digitalocean_droplet.worker_nodes.1.ipv4_address}"
worker3_ip = "${digitalocean_droplet.worker_nodes.2.ipv4_address}"
ingress1_ip = "${digitalocean_droplet.ingress_nodes.0.ipv4_address}"
ingress2_ip = "${digitalocean_droplet.ingress_nodes.1.ipv4_address}"
storage1_ip = "${digitalocean_droplet.storage_nodes.0.ipv4_address}"
storage2_ip = "${digitalocean_droplet.storage_nodes.1.ipv4_address}"
}
}
# A bootstrap node to execute Kismatic from.
resource "digitalocean_droplet" "bootstrap_node" {
image = "${var.image}"
name = "bootstrap"
region = "${var.region}"
size = "${var.droplet_size}"
ssh_keys = ["${digitalocean_ssh_key.default.id}"]
tags = ["${digitalocean_tag.cluster_tag.id}"]
private_networking = true
connection {
type = "ssh"
private_key = "${file("${path.module}/../ssh/cluster.pem")}"
user = "root"
timeout = "2m"
}
# ########################################################
# Upload all the files and directories required.
# ########################################################
provisioner "file" {
source = "${path.module}/../ssh/cluster.pem"
destination = "${var.install_dir}/cluster.pem"
}
provisioner "file" {
content = "${data.template_file.kismatic_cluster.rendered}"
destination = "${var.install_dir}/kismatic-cluster.yaml"
}
provisioner "file" {
source = "${path.module}/../Makefile"
destination = "${var.install_dir}/Makefile"
}
provisioner "file" {
source = "${path.module}/user-data/${var.kismatic_tar_file}"
destination = "${var.install_dir}/${var.kismatic_tar_file}"
}
provisioner "file" {
source = "${path.module}/user-data/bootstrap-script.sh"
destination = "${var.install_dir}/bootstrap-script.sh"
}
# ########################################################
# Execute the necessary commands to setup the cluster.
# ########################################################
provisioner "remote-exec" {
inline = [
"chmod +x /root/bootstrap-script.sh",
"${var.install_dir}/bootstrap-script.sh args",
]
}
# Extract the Kismatic tar file and setup both Kubectl and Helm
provisioner "remote-exec" {
inline = [
"tar -xvzf ${var.kismatic_tar_file}",
"cp helm /usr/local/bin/helm",
"cp kubectl /usr/local/bin/kubectl",
"echo 'source <(kubectl completion bash)' >> ~/.bashrc",
"cp kismatic /usr/local/bin/kismatic",
"rm ${var.kismatic_tar_file}"
]
}
}
#!/bin/bash
echo "Try to speed up the apt-get install"
sudo yum update -y
echo "Upgrade and install build-essential and other necessary packages."
sudo yum update -y
sudo yum install -y make git wget nano vim bash-completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment