-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcluster.tf
123 lines (103 loc) · 4.97 KB
/
cluster.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
##############################################################################
# Find valid IKS/ROKS Cluster versions for region
##############################################################################
data "ibm_container_cluster_versions" "cluster_versions" {}
##############################################################################
##############################################################################
# Cluster Locals
##############################################################################
locals {
worker_pools_map = module.dynamic_values.worker_pools_map # Convert list to map
clusters_map = module.dynamic_values.clusters_map # Convert list to map
latest_kube_version = {
openshift = "${data.ibm_container_cluster_versions.cluster_versions.valid_openshift_versions[length(data.ibm_container_cluster_versions.cluster_versions.valid_openshift_versions) - 1]}_openshift"
iks = data.ibm_container_cluster_versions.cluster_versions.valid_kube_versions[length(data.ibm_container_cluster_versions.cluster_versions.valid_kube_versions) - 1]
}
default_kube_version = {
openshift = "${data.ibm_container_cluster_versions.cluster_versions.default_openshift_version}_openshift"
iks = data.ibm_container_cluster_versions.cluster_versions.default_kube_version
}
}
##############################################################################
##############################################################################
# Create IKS/ROKS on VPC Cluster
##############################################################################
resource "ibm_container_vpc_cluster" "cluster" {
for_each = local.clusters_map
name = "${var.prefix}-${each.value.name}"
vpc_id = each.value.vpc_id
resource_group_id = local.resource_groups[each.value.resource_group]
flavor = each.value.machine_type
worker_count = each.value.workers_per_subnet
# if version is default or null then use default
# if version is latest then use latest
# otherwise use value
kube_version = (
lookup(each.value, "kube_version", null) == "default" || lookup(each.value, "kube_version", null) == null
? local.default_kube_version[each.value.kube_type]
: (lookup(each.value, "kube_version", null) == "latest" ? local.latest_kube_version[each.value.kube_type] : each.value.kube_version)
)
update_all_workers = lookup(each.value, "update_all_workers", null)
tags = var.tags
wait_till = var.wait_till
entitlement = each.value.entitlement
cos_instance_crn = each.value.cos_instance_crn
pod_subnet = each.value.pod_subnet
service_subnet = each.value.service_subnet
crk = each.value.boot_volume_crk_name == null ? null : module.key_management.key_map[each.value.boot_volume_crk_name].key_id
kms_instance_id = each.value.boot_volume_crk_name == null ? null : module.key_management.key_management_guid
lifecycle {
ignore_changes = [kube_version]
}
dynamic "zones" {
for_each = each.value.subnets
content {
subnet_id = zones.value["id"]
name = zones.value["zone"]
}
}
dynamic "kms_config" {
for_each = each.value.kms_config == null ? [] : [each.value.kms_config]
content {
crk_id = module.key_management.key_map[kms_config.value.crk_name].key_id
instance_id = module.key_management.key_management_guid
private_endpoint = kms_config.value.private_endpoint
}
}
disable_public_service_endpoint = true
timeouts {
create = "3h"
delete = "2h"
update = "3h"
}
}
resource "ibm_resource_tag" "cluster_tag" {
for_each = local.clusters_map
resource_id = ibm_container_vpc_cluster.cluster[each.key].crn
tag_type = "access"
tags = each.value.access_tags
}
##############################################################################
##############################################################################
# Create Worker Pools
##############################################################################
resource "ibm_container_vpc_worker_pool" "pool" {
for_each = local.worker_pools_map
vpc_id = each.value.vpc_id
resource_group_id = local.resource_groups[each.value.resource_group]
entitlement = each.value.entitlement
cluster = ibm_container_vpc_cluster.cluster[each.value.cluster_name].id
worker_pool_name = each.value.name
flavor = each.value.flavor
worker_count = each.value.workers_per_subnet
crk = each.value.boot_volume_crk_name == null ? null : module.key_management.key_map[each.value.boot_volume_crk_name].key_id
kms_instance_id = each.value.boot_volume_crk_name == null ? null : module.key_management.key_management_guid
dynamic "zones" {
for_each = each.value.subnets
content {
subnet_id = zones.value["id"]
name = zones.value["zone"]
}
}
}
##############################################################################