Skip to content

Commit

Permalink
terraform 0.12 compatible formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tillepille authored and solidnerd committed Oct 25, 2019
1 parent fc8df59 commit 0359e1f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 37 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ Please use the [issue tracker](https://github.com/solidnerd/terraform-k8s-hcloud


**Tested with**
- Terraform [v0.11.10](https://github.com/hashicorp/terraform/tree/v0.11.10)
- provider.hcloud [v1.6.0](https://github.com/terraform-providers/terraform-provider-hcloud/tree/v1.6.0)

- Terraform [v0.12.8](https://github.com/hashicorp/terraform/tree/v0.12.8)
- provider.hcloud [v1.12.0](https://github.com/terraform-providers/terraform-provider-hcloud)
19 changes: 10 additions & 9 deletions install-calico.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
resource "null_resource" "calico" {
count = "${var.calico_enabled ? 1 : 0}"
count = var.calico_enabled ? 1 : 0

connection {
host = "${hcloud_server.master.*.ipv4_address}"
private_key = "${file(var.ssh_private_key)}"
host = hcloud_server.master.*.ipv4_address
private_key = file(var.ssh_private_key)
}

provisioner "remote-exec" {
inline = <<EOF
kubectl apply -f https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/hosted/etcd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/rbac.yaml
kubectl apply -f https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/hosted/calico.yaml
EOF
inline = [
"kubectl apply -f https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/hosted/etcd.yaml",
"kubectl apply -f https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/rbac.yaml",
"kubectl apply -f https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/hosted/calico.yaml"
]
}

depends_on = ["hcloud_server.master"]
depends_on = [hcloud_server.master]
}

48 changes: 27 additions & 21 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
provider "hcloud" {
token = "${var.hcloud_token}"
token = var.hcloud_token
}

resource "hcloud_ssh_key" "k8s_admin" {
name = "k8s_admin"
public_key = "${file(var.ssh_public_key)}"
public_key = file(var.ssh_public_key)
}

resource "hcloud_server" "master" {
count = "${var.master_count}"
count = var.master_count
name = "master-${count.index + 1}"
server_type = "${var.master_type}"
image = "${var.master_image}"
ssh_keys = ["${hcloud_ssh_key.k8s_admin.id}"]
server_type = var.master_type
image = var.master_image
ssh_keys = [hcloud_ssh_key.k8s_admin.id]

connection {
private_key = "${file(var.ssh_private_key)}"
host = self.ipv4_address
type = "ssh"
private_key = file(var.ssh_private_key)
}

provisioner "file" {
Expand All @@ -29,7 +31,7 @@ resource "hcloud_server" "master" {
}

provisioner "remote-exec" {
inline = "DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/bootstrap.sh"
inline = ["DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/bootstrap.sh"]
}

provisioner "file" {
Expand All @@ -38,31 +40,33 @@ resource "hcloud_server" "master" {
}

provisioner "remote-exec" {
inline = "CORE_DNS=${var.core_dns} bash /root/master.sh"
inline = ["CORE_DNS=${var.core_dns} bash /root/master.sh"]
}

provisioner "local-exec" {
command = "bash scripts/copy-kubeadm-token.sh"

environment {
SSH_PRIVATE_KEY = "${var.ssh_private_key}"
environment = {
SSH_PRIVATE_KEY = var.ssh_private_key
SSH_USERNAME = "root"
SSH_HOST = "${hcloud_server.master.ipv4_address}"
SSH_HOST = hcloud_server.master[0].ipv4_address
TARGET = "${path.module}/secrets/"
}
}
}

resource "hcloud_server" "node" {
count = "${var.node_count}"
count = var.node_count
name = "node-${count.index + 1}"
server_type = "${var.node_type}"
image = "${var.node_image}"
depends_on = ["hcloud_server.master"]
ssh_keys = ["${hcloud_ssh_key.k8s_admin.id}"]
server_type = var.node_type
image = var.node_image
depends_on = [hcloud_server.master]
ssh_keys = [hcloud_ssh_key.k8s_admin.id]

connection {
private_key = "${file(var.ssh_private_key)}"
host = self.ipv4_address
type = "ssh"
private_key = file(var.ssh_private_key)
}

provisioner "file" {
Expand All @@ -76,17 +80,18 @@ resource "hcloud_server" "node" {
}

provisioner "remote-exec" {
inline = "DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/bootstrap.sh"
inline = ["DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/bootstrap.sh"]
}

provisioner "file" {
source = "${path.module}/secrets/kubeadm_join"
destination = "/tmp/kubeadm_join"

connection {
host = self.ipv4_address
type = "ssh"
user = "root"
private_key = "${file(var.ssh_private_key)}"
private_key = file(var.ssh_private_key)
}
}

Expand All @@ -96,6 +101,7 @@ resource "hcloud_server" "node" {
}

provisioner "remote-exec" {
inline = "bash /root/node.sh"
inline = ["bash /root/node.sh"]
}
}

5 changes: 3 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
output "node_ips" {
value = ["${hcloud_server.node.*.ipv4_address}"]
value = [hcloud_server.node.*.ipv4_address]
}

output "master_ips" {
value = ["${hcloud_server.master.*.ipv4_address}"]
value = [hcloud_server.master.*.ipv4_address]
}

10 changes: 7 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
variable "hcloud_token" {}
variable "hcloud_token" {
}

variable "master_count" {}
variable "master_count" {
}

variable "master_image" {
description = "Predefined Image that will be used to spin up the machines (Currently supported: ubuntu-16.04, debian-9,centos-7,fedora-27)"
Expand All @@ -12,7 +14,8 @@ variable "master_type" {
default = "cx11"
}

variable "node_count" {}
variable "node_count" {
}

variable "node_image" {
description = "Predefined Image that will be used to spin up the machines (Currently supported: ubuntu-16.04, debian-9,centos-7,fedora-27)"
Expand Down Expand Up @@ -49,3 +52,4 @@ variable "core_dns" {
variable "calico_enabled" {
default = false
}

4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 0359e1f

Please sign in to comment.