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

Commit ffef8a9

Browse files
author
Sean Sundberg
authored
Makes cluster login driven by 'login' flag (#22)
Signed-off-by: Sean Sundberg <[email protected]>
1 parent 1097a17 commit ffef8a9

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

main.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ locals {
5151
"kms",
5252
"hs-crypto"
5353
]
54+
cluster_config = var.login ? data.ibm_container_cluster_config.cluster[0].config_file_path : ""
5455
}
5556

5657
resource null_resource create_dirs {
@@ -196,3 +197,53 @@ data ibm_container_vpc_cluster config {
196197
alb_type = var.disable_public_endpoint ? "private" : "public"
197198
resource_group_id = data.ibm_resource_group.resource_group.id
198199
}
200+
201+
resource "null_resource" "list_tmp" {
202+
depends_on = [null_resource.create_dirs]
203+
204+
triggers = {
205+
always_run = timestamp()
206+
}
207+
208+
provisioner "local-exec" {
209+
command = "ls ${local.tmp_dir}"
210+
}
211+
}
212+
213+
214+
data ibm_container_cluster_config cluster_admin {
215+
count = var.login ? 1 : 0
216+
depends_on = [data.ibm_container_vpc_cluster.config, null_resource.list_tmp]
217+
218+
cluster_name_id = local.cluster_name
219+
admin = true
220+
resource_group_id = data.ibm_resource_group.resource_group.id
221+
config_dir = local.cluster_config_dir
222+
}
223+
224+
data ibm_container_cluster_config cluster {
225+
count = var.login ? 1 : 0
226+
depends_on = [
227+
data.ibm_container_vpc_cluster.config,
228+
null_resource.list_tmp,
229+
data.ibm_container_cluster_config.cluster_admin
230+
]
231+
232+
cluster_name_id = local.cluster_name
233+
resource_group_id = data.ibm_resource_group.resource_group.id
234+
config_dir = local.cluster_config_dir
235+
}
236+
237+
resource null_resource setup_kube_config {
238+
count = var.login ? 1 : 0
239+
depends_on = [null_resource.create_dirs, data.ibm_container_cluster_config.cluster]
240+
241+
provisioner "local-exec" {
242+
command = "${path.module}/scripts/wait-for-kubeconfig.sh"
243+
244+
environment = {
245+
KUBECONFIG = local.cluster_config
246+
}
247+
}
248+
}
249+

module.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,3 @@ versions:
7777
scope: module
7878
- name: ocp_entitlement
7979
scope: ignore
80-
- name: gitops_dir
81-
scope: global

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ variable "authorize_kms" {
118118
description = "Flag indicating that the authorization between the kms and the service should be created."
119119
default = true
120120
}
121+
122+
variable "login" {
123+
type = bool
124+
description = "Flag indicating that after the cluster is provisioned, the module should log into the cluster"
125+
default = false
126+
}

0 commit comments

Comments
 (0)