-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathocean.tf
139 lines (118 loc) · 4.76 KB
/
ocean.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
resource "spotinst_ocean_aks" "cluster" {
count = var.create_ocean ? 1 : 0
depends_on = [module.ocean-controller, azurerm_role_assignment.kubelet_contributor]
name = local.aks_cluster_name
controller_cluster_id = local.ocean_controller_cluster_id
acd_identifier = local.ocean_acd_identifier
aks_name = local.aks_cluster_name
ssh_public_key = local.public_ssh_key
user_name = local.username
aks_resource_group_name = var.resource_group_name
dynamic "managed_service_identity" {
for_each = var.client_id == "" || var.client_secret == "" ? ["identity"] : []
content {
resource_group_name = local.node_resource_group_name
name = local.kubelet_identity_name
}
}
}
data "azurerm_kubernetes_cluster_node_pool" "nodepool" {
count = var.create_ocean && length(local.node_pool_names) > 0 ? length(local.node_pool_names) : 0
depends_on = [module.aks]
resource_group_name = var.resource_group_name
kubernetes_cluster_name = local.aks_cluster_name
name = local.node_pool_names[count.index]
}
resource "spotinst_ocean_aks_virtual_node_group" "nodepool" {
count = var.create_ocean && length(local.node_pool_names) > 0 ? length(local.node_pool_names) : 0
name = local.node_pool_names[count.index]
ocean_id = spotinst_ocean_aks.cluster.*.id[0]
dynamic "label" {
for_each = merge(
data.azurerm_kubernetes_cluster_node_pool.nodepool[count.index].node_labels,
lookup(var.node_pools_labels, "all", {}),
lookup(var.node_pools_labels, local.node_pool_names[count.index], {}),
)
content {
key = label.key
value = label.value
}
}
dynamic "taint" {
for_each = flatten(concat(
data.azurerm_kubernetes_cluster_node_pool.nodepool[count.index].node_taints,
lookup(var.node_pools_taints, "all", []),
lookup(var.node_pools_taints, local.node_pool_names[count.index], []),
))
content {
key = lookup(taint.value, "key", null)
value = lookup(taint.value, "value", null)
effect = lookup(taint.value, "effect", null)
}
}
dynamic "resource_limits" {
for_each = data.azurerm_kubernetes_cluster_node_pool.nodepool.*.max_count[count.index] > 0 ? ["resource_limits"] : []
content {
max_instance_count = data.azurerm_kubernetes_cluster_node_pool.nodepool.*.max_count[count.index]
}
}
dynamic "autoscale" {
for_each = length(merge(
lookup(var.node_pools_headrooms, "all", {}),
lookup(var.node_pools_headrooms, local.node_pool_names[count.index], {}),
)) > 0 ? ["autoscale"] : []
content {
dynamic "autoscale_headroom" {
for_each = [
merge(
lookup(var.node_pools_headrooms, "all", {}),
lookup(var.node_pools_headrooms, local.node_pool_names[count.index], {}),
)
]
content {
cpu_per_unit = lookup(autoscale_headroom.value, "cpu_per_unit", null)
gpu_per_unit = lookup(autoscale_headroom.value, "gpu_per_unit", null)
memory_per_unit = lookup(autoscale_headroom.value, "memory_per_unit", null)
num_of_units = lookup(autoscale_headroom.value, "num_of_units", null)
}
}
}
}
launch_specification {
os_disk {
size_gb = data.azurerm_kubernetes_cluster_node_pool.nodepool[count.index].os_disk_size_gb
type = var.os_disk_type # see: https://github.com/Azure/AKS/issues/580
}
dynamic "tag" {
for_each = merge(
data.azurerm_kubernetes_cluster_node_pool.nodepool[count.index].tags,
lookup(var.node_pools_tags, "all", {}),
lookup(var.node_pools_tags, local.node_pool_names[count.index], {}),
)
content {
key = tag.key
value = tag.value
}
}
}
}
module "ocean-controller" {
source = "spotinst/ocean-controller/spotinst"
version = "~> 0.40"
depends_on = [module.aks]
create_controller = var.create_controller && var.create_ocean
spotinst_token = var.spotinst_token
spotinst_account = var.spotinst_account
aks_connector_enabled = var.controller_aks_connector_enabled
base_url = var.controller_base_url
disable_auto_update = var.controller_disable_auto_update
enable_csr_approval = var.controller_enable_csr_approval
image_pull_policy = var.controller_image_pull_policy
image_pull_secrets = var.controller_image_pull_secrets
proxy_url = var.controller_proxy_url
resources_limits = var.controller_resources_limits
resources_requests = var.controller_resources_requests
tolerations = var.controller_tolerations
cluster_identifier = local.ocean_controller_cluster_id
acd_identifier = local.ocean_acd_identifier
}