generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
292 lines (236 loc) · 9.9 KB
/
main.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
locals {
# sleep times definition
sleep_time_catalog_create = "60s"
sleep_time_operator_create = "120s"
sleep_time_queue_manager_create = "120s"
# helm chart names
ibm_operator_catalog_chart = "ibm-operator-catalog"
ibm_mq_operator_chart = "mq-operator"
ibm_mq_operator_group_chart = "mq-operator-group"
ibm_mq_queue_manager_chart = "mq-queue-manager"
# validation of ibm_mq_operator_target_namespace - if null the value of ibm_mq_operator_namespace must be equal to "openshift-operators" https://www.ibm.com/docs/en/ibm-mq/9.3?topic=imo-installing-mq-operator-using-red-hat-openshift-cli
default_ibm_mq_operator_namespace = "openshift-operators"
operator_target_namespace_cnd = var.ibm_mq_operator_target_namespace == null && var.ibm_mq_operator_namespace != local.default_ibm_mq_operator_namespace
operator_target_namespace_msg = "if input var ibm_mq_operator_target_namespace is null the value of ibm_mq_operator_namespace must be equal to ${local.default_ibm_mq_operator_namespace}"
# tflint-ignore: terraform_unused_declarations
operator_target_namespace_chk = regex("^${local.operator_target_namespace_msg}$", (!local.operator_target_namespace_cnd ? local.operator_target_namespace_msg : ""))
# tflint-ignore: terraform_unused_declarations
validate_queue_manager_name = var.create_queue_manager && var.queue_manager_name == null ? tobool("if var.create_queue_manager is true then var.queue_manager_name must not be null.") : true
# tflint-ignore: terraform_unused_declarations
validate_queue_manager_license = var.create_queue_manager && var.queue_manager_license == null ? tobool("if var.create_queue_manager is true then var.queue_manager_license must not be null.") : true
# tflint-ignore: terraform_unused_declarations
validate_queue_manager_license_usage = var.create_queue_manager && var.queue_manager_license_usage == null ? tobool("if var.create_queue_manager is true then var.queue_manager_license_usage must not be null.") : true
# tflint-ignore: terraform_unused_declarations
validate_queue_manager_version = var.create_queue_manager && var.queue_manager_version == null ? tobool("if var.create_queue_manager is true then var.queue_manager_version must not be null.") : true
# tflint-ignore: terraform_unused_declarations
validate_create_ibm_mq_queue_manager_namespace = var.create_ibm_mq_queue_manager_namespace && !var.create_queue_manager ? tobool("if var.create_ibm_mq_queue_manager_namespace is true then var.create_queue_manager has to be true as well.") : true
# tflint-ignore: terraform_unused_declarations
validate_ibm_mq_queue_manager_namespace = var.create_ibm_mq_queue_manager_namespace && var.ibm_mq_queue_manager_namespace == null ? tobool("if var.create_ibm_mq_queue_manager_namespace is true then var.ibm_mq_queue_manager_namespace must not be null.") : true
}
data "ibm_container_cluster_config" "cluster_config" {
cluster_name_id = var.cluster_id
config_dir = "${path.module}/kubeconfig"
endpoint_type = var.cluster_config_endpoint_type != "default" ? var.cluster_config_endpoint_type : null
}
# creating the namespace to deploy the helm releases to install the IBM MQ Operator
resource "kubernetes_namespace" "helm_release_operator_namespace" {
metadata {
name = var.operator_helm_release_namespace
}
timeouts {
delete = "30m"
}
lifecycle {
ignore_changes = [
metadata[0].annotations,
metadata[0].labels
]
}
}
locals {
ibm_operator_catalog_version = "v1.25-20240202.161709-9DAF3E648@sha256:92e28be4af60f68c656f52b2445aafcc052fcd0390479b868c5b0ba2d465a25a" # datasource: icr.io/cpopen/ibm-operator-catalog
ibm_operator_catalog_path = "icr.io/cpopen/ibm-operator-catalog"
}
# if add_ibm_operator_catalog is true going on with adding the IBM Operator Catalog source
resource "helm_release" "ibm_operator_catalog" {
depends_on = [kubernetes_namespace.helm_release_operator_namespace]
count = var.add_ibm_operator_catalog == true ? 1 : 0
name = "ibm-operator-catalog-helm-release"
chart = "${path.module}/chart/${local.ibm_operator_catalog_chart}"
namespace = var.operator_helm_release_namespace
create_namespace = false
timeout = 300
force_update = true
cleanup_on_fail = false
wait = true
recreate_pods = true
disable_openapi_validation = false
set {
name = "image.path"
type = "string"
value = local.ibm_operator_catalog_path
}
set {
name = "image.version"
type = "string"
value = local.ibm_operator_catalog_version
}
}
# waiting for the catalog to be configured and correctly pulled
resource "time_sleep" "wait_catalog" {
depends_on = [helm_release.ibm_operator_catalog[0]]
count = var.add_ibm_operator_catalog == true ? 1 : 0
create_duration = local.sleep_time_catalog_create
}
# if ibm_mq_operator_target_namespace != null the operator group must be created
resource "helm_release" "ibm_mq_operator_group" {
count = var.ibm_mq_operator_target_namespace != null ? 1 : 0
depends_on = [time_sleep.wait_catalog[0], kubernetes_namespace.helm_release_operator_namespace]
name = "ibm-mq-operator-group-helm-release"
chart = "${path.module}/chart/${local.ibm_mq_operator_group_chart}"
namespace = var.operator_helm_release_namespace
create_namespace = false
timeout = 300
force_update = true
cleanup_on_fail = false
wait = true
recreate_pods = true
disable_openapi_validation = false
set {
name = "operatornamespace"
type = "string"
value = var.ibm_mq_operator_namespace
}
set {
name = "operatortargetnamespace"
type = "string"
value = var.ibm_mq_operator_target_namespace
}
}
resource "kubernetes_namespace" "ibm_mq_operator_namespace" {
count = var.create_ibm_mq_operator_namespace == true ? 1 : 0
metadata {
name = var.ibm_mq_operator_namespace
}
timeouts {
delete = "30m"
}
lifecycle {
ignore_changes = [
metadata[0].annotations,
metadata[0].labels
]
}
}
resource "helm_release" "ibm_mq_operator" {
depends_on = [time_sleep.wait_catalog[0], helm_release.ibm_mq_operator_group[0], kubernetes_namespace.ibm_mq_operator_namespace[0]]
name = "ibm-mq-operator-helm-release"
chart = "${path.module}/chart/${local.ibm_mq_operator_chart}"
namespace = var.operator_helm_release_namespace
create_namespace = false
timeout = 300
force_update = true
cleanup_on_fail = false
wait = true
recreate_pods = true
disable_openapi_validation = false
set {
name = "operatornamespace"
type = "string"
value = var.ibm_mq_operator_namespace
}
provisioner "local-exec" {
command = "${path.module}/scripts/approve-install-plan.sh ${var.ibm_mq_operator_namespace}"
interpreter = ["/bin/bash", "-c"]
environment = {
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
}
}
}
resource "time_sleep" "wait_ibm_mq_operator" {
depends_on = [helm_release.ibm_mq_operator]
create_duration = local.sleep_time_operator_create
}
##############################################################################
# Confirm websphere operator is operational
##############################################################################
resource "null_resource" "confirm_ibm_mq_operator_operational" {
depends_on = [time_sleep.wait_ibm_mq_operator]
provisioner "local-exec" {
command = "${path.module}/scripts/confirm-ibm-mq-operator-operational.sh ${var.ibm_mq_operator_namespace}"
interpreter = ["/bin/bash", "-c"]
environment = {
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
}
}
}
##############################################################################
# Queue Manager
##############################################################################
resource "kubernetes_namespace" "ibm_mq_queue_manager_namespace" {
count = var.create_ibm_mq_queue_manager_namespace == true ? 1 : 0
metadata {
name = var.ibm_mq_queue_manager_namespace
}
timeouts {
delete = "30m"
}
lifecycle {
ignore_changes = [
metadata[0].annotations,
metadata[0].labels
]
}
}
resource "helm_release" "ibm_mq_queue_manager" {
depends_on = [helm_release.ibm_mq_operator, kubernetes_namespace.ibm_mq_queue_manager_namespace[0]]
count = var.create_queue_manager == true ? 1 : 0
name = "ibm-mq-queue-manager-helm-release"
chart = "${path.module}/chart/${local.ibm_mq_queue_manager_chart}"
namespace = var.operator_helm_release_namespace
create_namespace = false
timeout = 300
force_update = true
cleanup_on_fail = false
wait = true
recreate_pods = true
disable_openapi_validation = false
set {
name = "queuemanagernamespace"
type = "string"
value = var.ibm_mq_queue_manager_namespace
}
set {
name = "queuemanagername"
type = "string"
value = var.queue_manager_name
}
set {
name = "queuemanagerlicense"
type = "string"
value = var.queue_manager_license
}
set {
name = "queuemanagerlicenseusage"
type = "string"
value = var.queue_manager_license_usage
}
set {
name = "queuemanagerversion"
type = "string"
value = var.queue_manager_version
}
}
resource "time_sleep" "wait_ibm_mq_queue_manager" {
depends_on = [helm_release.ibm_mq_queue_manager[0]]
create_duration = local.sleep_time_queue_manager_create
}
data "external" "mq_queue_manager_url" {
depends_on = [time_sleep.wait_ibm_mq_queue_manager]
program = ["/bin/bash", "${path.module}/scripts/get-mq-queue-manager-web-url.sh"]
query = {
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
MQQUEUEMANAGERNAME = var.queue_manager_name
MQQUEUEMANAGERNAMESPACE = var.ibm_mq_queue_manager_namespace
}
}