Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit f905fb5

Browse files
authored
Merge pull request #47 from Charliekenney23/0.12-upgrade
[WIP] upgrade to terraform 0.12
2 parents a3ab9ac + 2d91f6d commit f905fb5

File tree

12 files changed

+119
-113
lines changed

12 files changed

+119
-113
lines changed

example/main.tf

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module "linode_k8s" {
1818

1919
version = "0.1.0"
2020

21-
nodes = "${var.nodes}"
22-
linode_token = "${var.linode_token}"
21+
nodes = var.nodes
22+
linode_token = var.linode_token
2323
}
2424

2525
variable "nodes" {
@@ -35,7 +35,7 @@ variable "linode_domain" {
3535
}
3636

3737
provider "kubernetes" {
38-
config_path = "${module.linode_k8s.kubectl_config}"
38+
config_path = module.linode_k8s.kubectl_config
3939
}
4040

4141
resource "kubernetes_service_account" "tiller" {
@@ -46,7 +46,7 @@ resource "kubernetes_service_account" "tiller" {
4646
}
4747

4848
resource "kubernetes_cluster_role_binding" "tiller" {
49-
depends_on = ["kubernetes_service_account.tiller"]
49+
depends_on = [kubernetes_service_account.tiller]
5050

5151
metadata {
5252
name = "tiller"
@@ -65,11 +65,11 @@ resource "kubernetes_cluster_role_binding" "tiller" {
6565
}
6666

6767
resource null_resource "tiller" {
68-
depends_on = ["kubernetes_cluster_role_binding.tiller"]
68+
depends_on = [kubernetes_cluster_role_binding.tiller]
6969

7070
provisioner "local-exec" {
7171
environment {
72-
KUBECONFIG = "${module.linode_k8s.kubectl_config}"
72+
KUBECONFIG = module.linode_k8s.kubectl_config
7373
}
7474

7575
command = "helm init --service-account tiller --wait"
@@ -82,7 +82,7 @@ provider "helm" {
8282
install_tiller = false
8383

8484
kubernetes {
85-
config_path = "${module.linode_k8s.kubectl_config}"
85+
config_path = module.linode_k8s.kubectl_config
8686
}
8787
}
8888

@@ -92,7 +92,7 @@ resource "helm_repository" "incubator" {
9292
}
9393

9494
resource "helm_release" "wordpress" {
95-
depends_on = ["helm_release.mysqlha"]
95+
depends_on = [helm_release.mysqlha]
9696
name = "stable"
9797
chart = "wordpress"
9898
version = "5.0.1"
@@ -105,7 +105,7 @@ resource "helm_release" "wordpress" {
105105
}
106106

107107
resource "helm_release" "mysqlha" {
108-
name = "${helm_repository.incubator.name}"
108+
name = helm_repository.incubator.name
109109
chart = "mysqlha"
110110
version = "0.4.0"
111111
values = ["${file("${path.module}/values/mysqlha.values.yaml")}"]
@@ -121,7 +121,7 @@ resource "helm_release" "traefik" {
121121
name = "service.annotations.external-dns\\.alpha\\.kubernetes\\.io/hostname\\.io/hostname"
122122
value = "dashboard.${var.linode_domain}"
123123
}
124-
124+
125125
set {
126126
name = "dashboard.domain"
127127
value = "dashboard.${var.linode_domain}"

main.tf

+31-40
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
provider "linode" {
2-
token = "${var.linode_token}"
3-
version = "1.5.0"
4-
}
5-
6-
provider "external" {
7-
version = "1.0.0"
8-
}
9-
101
resource "null_resource" "preflight-checks" {
112
# Force re-run
12-
triggers {
13-
key = "${uuid()}"
3+
triggers = {
4+
key = uuid()
145
}
156

167
provisioner "local-exec" {
@@ -20,61 +11,61 @@ resource "null_resource" "preflight-checks" {
2011

2112
module "masters" {
2213
source = "./modules/masters"
23-
label_prefix = "${var.cluster_name == "" ? terraform.workspace : var.cluster_name}"
14+
label_prefix = var.cluster_name == "" ? terraform.workspace : var.cluster_name
2415
node_class = "master"
25-
node_count = "${var.masters}"
26-
node_type = "${var.server_type_master}"
27-
linode_token = "${var.linode_token}"
16+
node_count = var.masters
17+
node_type = var.server_type_master
18+
linode_token = var.linode_token
2819

29-
k8s_version = "${var.k8s_version}"
30-
crictl_version = "${var.crictl_version}"
31-
k8s_feature_gates = "${var.k8s_feature_gates}"
32-
cni_version = "${var.cni_version}"
33-
ssh_public_key = "${var.ssh_public_key}"
34-
region = "${var.region}"
35-
linode_group = "${var.cluster_name}"
20+
k8s_version = var.k8s_version
21+
crictl_version = var.crictl_version
22+
k8s_feature_gates = var.k8s_feature_gates
23+
cni_version = var.cni_version
24+
ssh_public_key = var.ssh_public_key
25+
region = var.region
26+
linode_group = var.cluster_name
3627

3728
//todo variable instead of workspace?
38-
cluster_name = "${var.cluster_name == "" ? terraform.workspace : var.cluster_name}"
29+
cluster_name = var.cluster_name == "" ? terraform.workspace : var.cluster_name
3930
}
4031

4132
module "nodes" {
4233
source = "./modules/nodes"
43-
label_prefix = "${var.cluster_name == "" ? terraform.workspace : var.cluster_name}"
34+
label_prefix = var.cluster_name == "" ? terraform.workspace : var.cluster_name
4435
node_class = "node"
45-
node_count = "${var.nodes}"
46-
node_type = "${var.server_type_node}"
36+
node_count = var.nodes
37+
node_type = var.server_type_node
4738

48-
k8s_version = "${var.k8s_version}"
49-
crictl_version = "${var.crictl_version}"
50-
k8s_feature_gates = "${var.k8s_feature_gates}"
51-
cni_version = "${var.cni_version}"
52-
ssh_public_key = "${var.ssh_public_key}"
53-
region = "${var.region}"
54-
linode_group = "${var.cluster_name}"
55-
kubeadm_join_command = "${module.masters.kubeadm_join_command}"
39+
k8s_version = var.k8s_version
40+
crictl_version = var.crictl_version
41+
k8s_feature_gates = var.k8s_feature_gates
42+
cni_version = var.cni_version
43+
ssh_public_key = var.ssh_public_key
44+
region = var.region
45+
linode_group = var.cluster_name
46+
kubeadm_join_command = module.masters.kubeadm_join_command
5647
}
5748

5849
resource "null_resource" "local_kubectl" {
5950
// todo
60-
depends_on = ["module.masters"]
51+
depends_on = [module.masters]
6152

6253
provisioner "local-exec" {
6354
command = "${path.module}/scripts/local/kubectl-conf.sh ${terraform.workspace} ${module.masters.k8s_master_public_ip} ${module.masters.k8s_master_private_ip} ${var.ssh_public_key}"
64-
on_failure = "continue"
55+
on_failure = continue
6556
}
6657
}
6758

6859
resource "null_resource" "update-agent" {
69-
depends_on = ["module.masters", "module.nodes"]
60+
depends_on = [module.masters, module.nodes]
7061

71-
triggers {
72-
cluster_ips = "${"${module.masters.k8s_master_public_ip} ${join(" ", module.nodes.nodes_public_ip)}"}"
62+
triggers = {
63+
cluster_ips = "${module.masters.k8s_master_public_ip} ${join(" ", module.nodes.nodes_public_ip)}"
7364
}
7465

7566
provisioner "remote-exec" {
7667
connection {
77-
host = "${module.masters.k8s_master_public_ip}"
68+
host = module.masters.k8s_master_public_ip
7869
user = "core"
7970
}
8071

modules/instances/main.tf

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
locals {
2+
root_user = "core"
3+
}
4+
15
data "linode_instance_type" "type" {
2-
id = "${var.node_type}"
6+
id = var.node_type
37
}
48

59
resource "linode_instance" "instance" {
6-
count = "${var.node_count}"
7-
region = "${var.region}"
10+
count = var.node_count
11+
region = var.region
812
label = "${var.label_prefix == "" ? "" : "${var.label_prefix}-"}${var.node_class}-${count.index + 1}"
9-
group = "${var.linode_group}"
10-
type = "${var.node_type}"
11-
private_ip = "${var.private_ip}"
13+
group = var.linode_group
14+
type = var.node_type
15+
private_ip = var.private_ip
1216

1317
disk {
1418
label = "boot"
15-
size = "${data.linode_instance_type.type.disk}"
16-
authorized_keys = ["${chomp(file(var.ssh_public_key))}"]
19+
size = data.linode_instance_type.type.disk
20+
authorized_keys = [chomp(file(var.ssh_public_key))]
1721
image = "linode/containerlinux"
1822
}
1923

2024
config {
21-
label = "${var.node_class}"
25+
label = var.node_class
2226

2327
kernel = "linode/direct-disk"
2428

2529
devices {
26-
sda = {
30+
sda {
2731
disk_label = "boot"
2832
}
2933
}
@@ -35,7 +39,8 @@ resource "linode_instance" "instance" {
3539
]
3640

3741
connection {
38-
user = "core"
42+
host = self.ip_address
43+
user = local.root_user
3944
timeout = "300s"
4045
}
4146
}
@@ -45,7 +50,8 @@ resource "linode_instance" "instance" {
4550
destination = "/home/core/init/"
4651

4752
connection {
48-
user = "core"
53+
host = self.ip_address
54+
user = local.root_user
4955
timeout = "300s"
5056
}
5157
}
@@ -59,7 +65,8 @@ resource "linode_instance" "instance" {
5965
]
6066

6167
connection {
62-
user = "core"
68+
host = self.ip_address
69+
user = local.root_user
6370
timeout = "300s"
6471
}
6572
}

modules/instances/outputs.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// todo: ha, return nb address
22
output "public_ip_address" {
3-
depends_on = ["linode_instance.instance.0"]
3+
depends_on = [linode_instance.instance[0]]
44
description = "Public IP Address of the first instance in the group"
5-
value = "${element(concat(linode_instance.instance.*.ip_address, list("")), 0)}"
5+
value = element(concat(linode_instance.instance.*.ip_address, list("")), 0)
66
}
77

88
// todo: this doesnt make sense in ha -- return all?
99
output "private_ip_address" {
1010
description = "Private IP Address of the first instance in the group"
11-
depends_on = ["linode_instance.instance.0"]
12-
value = "${element(concat(linode_instance.instance.*.private_ip_address, list("")), 0)}"
11+
depends_on = [linode_instance.instance[0]]
12+
value = element(concat(linode_instance.instance.*.private_ip_address, list("")), 0)
1313
}
1414

1515
output "nodes_public_ip" {
16-
depends_on = ["linode_instance.instance.*"]
16+
depends_on = [linode_instance.instance]
1717
description = "Public IP Address of the instance(s)"
18-
value = "${concat(linode_instance.instance.*.ip_address)}"
18+
value = concat(linode_instance.instance.*.ip_address)
1919
}

modules/masters/main.tf

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module "master_instance" {
22
source = "../instances"
3-
label_prefix = "${var.label_prefix}"
4-
node_type = "${var.node_type}"
3+
label_prefix = var.label_prefix
4+
node_type = var.node_type
55
node_count = "1" // HA not supported yet
66
node_class = "master"
7-
linode_group = "${var.linode_group}"
7+
linode_group = var.linode_group
88
private_ip = "true"
99
use_public = "true" // rename this var, sent to kubeadm
1010

11-
k8s_version = "${var.k8s_version}"
12-
k8s_feature_gates = "${var.k8s_feature_gates}"
13-
cni_version = "${var.cni_version}"
14-
crictl_version = "${var.crictl_version}"
15-
ssh_public_key = "${var.ssh_public_key}"
16-
region = "${var.region}"
11+
k8s_version = var.k8s_version
12+
k8s_feature_gates = var.k8s_feature_gates
13+
cni_version = var.cni_version
14+
crictl_version = var.crictl_version
15+
ssh_public_key = var.ssh_public_key
16+
region = var.region
1717
}
1818

1919
resource "null_resource" "masters_provisioner" {
20-
depends_on = ["module.master_instance"]
20+
depends_on = [module.master_instance]
2121

2222
provisioner "remote-exec" {
2323
inline = [
@@ -27,7 +27,7 @@ resource "null_resource" "masters_provisioner" {
2727
connection {
2828
user = "core"
2929
timeout = "300s"
30-
host = "${module.master_instance.public_ip_address}"
30+
host = module.master_instance.public_ip_address
3131
}
3232
}
3333

@@ -38,7 +38,7 @@ resource "null_resource" "masters_provisioner" {
3838
connection {
3939
user = "core"
4040
timeout = "300s"
41-
host = "${module.master_instance.public_ip_address}"
41+
host = module.master_instance.public_ip_address
4242
}
4343
}
4444

@@ -60,7 +60,7 @@ resource "null_resource" "masters_provisioner" {
6060
connection {
6161
user = "core"
6262
timeout = "300s"
63-
host = "${module.master_instance.public_ip_address}"
63+
host = module.master_instance.public_ip_address
6464
}
6565
}
6666
}
@@ -69,8 +69,8 @@ data "external" "kubeadm_join" {
6969
program = ["${path.module}/scripts/local/kubeadm-token.sh"]
7070

7171
query = {
72-
host = "${module.master_instance.public_ip_address}"
72+
host = module.master_instance.public_ip_address
7373
}
7474

75-
depends_on = ["null_resource.masters_provisioner"]
75+
depends_on = [null_resource.masters_provisioner]
7676
}

modules/masters/outputs.tf

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
output "k8s_master_public_ip" {
2-
depends_on = ["module.master_instance"]
2+
depends_on = [module.master_instance]
33
description = "Public IP Address of the master node"
4-
value = "${module.master_instance.public_ip_address}"
4+
value = module.master_instance.public_ip_address
55
}
66

77
output "k8s_master_private_ip" {
8-
depends_on = ["module.master_instance"]
8+
depends_on = [module.master_instance]
99
description = "Private IP Address of the master node"
10-
value = "${module.master_instance.private_ip_address}"
10+
value = module.master_instance.private_ip_address
1111
}
1212

1313
locals {
1414
result = {
1515
command = ""
1616
}
1717

18-
kubeadm_join_results = "${concat(data.external.kubeadm_join.*.result, list(local.result))}"
19-
kubeadm_join_command = "${lookup(local.kubeadm_join_results["0"], "command", "")}"
18+
kubeadm_join_results = concat(data.external.kubeadm_join.*.result, list(local.result))
19+
kubeadm_join_command = lookup(local.kubeadm_join_results["0"], "command", "")
2020
}
2121

2222
output "kubeadm_join_command" {
23-
depends_on = ["null_resource.masters_provisioner"]
23+
depends_on = [null_resource.masters_provisioner]
2424
description = "kubeadm join command that can be used to add a node to the cluster"
25-
value = "${local.kubeadm_join_command}"
25+
value = local.kubeadm_join_command
2626
}

0 commit comments

Comments
 (0)