-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathicp-deploy.tf
194 lines (157 loc) · 7.85 KB
/
icp-deploy.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
locals {
icppassword = "${var.icppassword != "" ? "${var.icppassword}" : "${random_id.adminpassword.hex}"}"
registry_server = "${var.registry_server != "" ? "${var.registry_server}" : "${var.instance_name}-${random_id.clusterid.hex}-cluster"}"
namespace = "${dirname(var.icp_inception_image)}" # This will typically return ibmcom
# The final image repo will be either interpolated from what supplied in icp_inception_image or
image_repo = "${var.registry_server == "" ? "" : "${local.registry_server}/${local.namespace}"}"
icp-version = "${format("%s%s%s", "${local.docker_username != "" ? "${local.docker_username}:${local.docker_password}@" : ""}",
"${var.registry_server != "" ? "${var.registry_server}/" : ""}",
"${var.icp_inception_image}")}"
# If we're using external registry we need to be supplied registry_username and registry_password
docker_username = "${var.registry_username != "" ? var.registry_username : ""}"
docker_password = "${var.registry_password != "" ? var.registry_password : ""}"
# This is just to have a long list of disabled items to use in icp-deploy.tf
disabled_list = "${list("disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled","disabled")}"
disabled_management_services = "${zipmap(var.disabled_management_services, slice(local.disabled_list, 0, length(var.disabled_management_services)))}"
}
resource "random_id" "adminpassword" {
byte_length = "16"
}
resource "aws_s3_bucket_object" "icp_cert_crt" {
count = "${var.user_provided_cert_dns != "" ? 1 : 0}"
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "cfc-certs/icp-auth.crt"
source = "${path.module}/cfc-certs/icp-auth.crt"
}
resource "aws_s3_bucket_object" "icp_cert_key" {
count = "${var.user_provided_cert_dns != "" ? 1 : 0}"
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "cfc-certs/icp-auth.key"
source = "${path.module}/cfc-certs/icp-auth.key"
}
resource "aws_s3_bucket_object" "icp_config_yaml" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "icp-terraform-config.yaml"
content = <<EOF
management_services:
${join("\n", formatlist(" %v: disabled", var.disabled_management_services))}
EOF
}
resource "aws_s3_bucket_object" "terraform_tfvars" {
bucket = "${aws_s3_bucket.icp_config_backup.id}"
key = "terraform.tfvars"
content = <<EOF
boot-node = "${element(aws_network_interface.mastervip.*.private_ip, 0)}"
icp-host-groups = {
master = [
${join(",", formatlist("\"%v\"", aws_network_interface.mastervip.*.private_ip))}
]
proxy = [
${var.proxy["nodes"] > 0 ?
join(",", formatlist("\"%v\"", aws_network_interface.proxyvip.*.private_ip)) :
join(",", formatlist("\"%v\"", aws_network_interface.mastervip.*.private_ip))
}
]
worker = [
${join(",", formatlist("\"%v\"", aws_instance.icpnodes.*.private_ip))}
]
// make the master nodes managements nodes if we don't have any specified
management = [
${var.management["nodes"] > 0 ?
join(",", formatlist("\"%v\"", aws_instance.icpmanagement.*.private_ip)) :
join(",", formatlist("\"%v\"", aws_network_interface.mastervip.*.private_ip))
}
]
va = [
${join(",", formatlist("\"%v\"", aws_instance.icpva.*.private_ip))}
]
}
# Provide desired ICP version to provision
icp-inception = "${local.icp-version}"
/* Workaround for terraform issue #10857
When this is fixed, we can work this out automatically */
cluster_size = "${1 + var.master["nodes"] + var.worker["nodes"] + var.proxy["nodes"] + var.management["nodes"] + var.va["nodes"]}"
###################################################################################################################################
## You can feed in arbitrary configuration items in the icp_configuration map.
## Available configuration items availble from https://www.ibm.com/support/knowledgecenter/SSBS6K_3.1.0/installing/config_yaml.html
icp_configuration = {
network_cidr = "${var.icp_network_cidr}"
service_cluster_ip_range = "${var.icp_service_network_cidr}"
proxy_lb_address = "${aws_lb.icp-proxy.dns_name}"
cluster_lb_address = "${aws_lb.icp-console.dns_name}"
cluster_CA_domain = "${var.user_provided_cert_dns != "" ? var.user_provided_cert_dns : aws_lb.icp-console.dns_name}"
cluster_name = "${var.instance_name}-${random_id.clusterid.hex}-cluster"
calico_ip_autodetection_method = "interface=eth0"
kubelet_nodename = "fqdn"
${var.use_aws_cloudprovider ? "
cloud_provider = \"aws\"" : "" }
calico_tunnel_mtu = "8981"
# An admin password will be generated if not supplied in terraform.tfvars
default_admin_password = "${local.icppassword}"
# This is the list of disabled management services
#management_services = ${jsonencode(local.disabled_management_services)}
private_registry_enabled = "${var.registry_server != "" ? "true" : "false" }"
private_registry_server = "${local.registry_server}"
image_repo = "${local.image_repo}" # Will either be our private repo or external repo
docker_username = "${local.docker_username}" # Will either be username generated by us or supplied by user
docker_password = "${local.docker_password}" # Will either be username generated by us or supplied by user
}
# because not everything fits into the above map which is string-only key-value paris, provide a separate
# config file with complex types to be merged
icp_config_file = "./icp-terraform-config.yaml"
# We will let terraform generate a new ssh keypair
# for boot master to communicate with worker and proxy nodes
# during ICP deployment
generate_key = true
# SSH user and key for terraform to connect to newly created VMs
# ssh_key is the private key corresponding to the public assumed to be included in the template
ssh_user = "icpdeploy"
ssh_key_base64 = "${base64encode(tls_private_key.installkey.private_key_pem)}"
ssh_agent = false
EOF
}
resource "tls_private_key" "installkey" {
algorithm = "RSA"
}
# kick off the installer from the bastion node, if one exists. otherwise it will get kicked off from cloud-init
resource "null_resource" "start_install" {
# trigger a reinstall if the cluster config changes
triggers {
terraform_tfvars_contents = "${aws_s3_bucket_object.terraform_tfvars.content}"
icp_config_yaml_contents = "${aws_s3_bucket_object.icp_config_yaml.content}"
}
count = "${var.bastion["nodes"] != 0 ? 1 : 0}"
provisioner "remote-exec" {
connection {
host = "${aws_instance.icpmaster.0.private_ip}"
user = "icpdeploy"
private_key = "${tls_private_key.installkey.private_key_pem}"
bastion_host = "${aws_instance.bastion.0.public_ip}"
}
inline = [
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 1; done",
"sudo /tmp/icp_scripts/start_install.sh -i ${local.icp-version} -b ${aws_s3_bucket.icp_config_backup.id} ${local.image_package_uri != "" ? "-c ${local.image_package_uri}" : "" }"
]
}
}
output "ICP Console ELB DNS (internal)" {
value = "${aws_lb.icp-console.dns_name}"
}
output "ICP Proxy ELB DNS (internal)" {
value = "${aws_lb.icp-proxy.dns_name}"
}
output "ICP Console URL" {
value = "https://${var.user_provided_cert_dns != "" ? var.user_provided_cert_dns : aws_lb.icp-console.dns_name}:8443"
}
output "ICP Registry ELB URL" {
value = "https://${aws_lb.icp-console.dns_name}:8500"
}
output "ICP Kubernetes API URL" {
value = "https://${aws_lb.icp-console.dns_name}:8001"
}
output "ICP Admin Username" {
value = "admin"
}
output "ICP Admin Password" {
value = "${local.icppassword}"
}