Skip to content

Commit 7e79409

Browse files
OguzPastirmacihyder
authored andcommitted
Update operator and bastion cloud inits
1 parent abf66a2 commit 7e79409

File tree

8 files changed

+80
-12
lines changed

8 files changed

+80
-12
lines changed

module-bastion.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module "bastion" {
4646
compartment_id = local.compartment_id
4747

4848
# Bastion
49+
await_cloudinit = var.bastion_await_cloudinit
4950
assign_dns = var.assign_dns
5051
availability_domain = coalesce(var.bastion_availability_domain, lookup(local.ad_numbers_to_names, local.ad_numbers[0]))
5152
bastion_image_os_version = var.bastion_image_os_version
@@ -87,4 +88,4 @@ output "bastion_public_ip" {
8788
output "ssh_to_bastion" {
8889
description = "SSH command for bastion host"
8990
value = local.bastion_ssh_command
90-
}
91+
}

module-operator.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ module "operator" {
5454
bastion_user = var.bastion_user
5555

5656
# Operator
57+
await_cloudinit = var.operator_await_cloudinit
5758
assign_dns = var.assign_dns
5859
availability_domain = coalesce(var.operator_availability_domain, lookup(local.ad_numbers_to_names, local.ad_numbers[0]))
5960
cloud_init = var.operator_cloud_init
6061
image_id = local.operator_image_id
6162
install_cilium = var.cilium_install
6263
install_helm = var.operator_install_helm
64+
install_helm_from_repo = var.operator_install_helm_from_repo
65+
install_oci_cli_from_repo = var.operator_install_oci_cli_from_repo
6366
install_istioctl = var.operator_install_istioctl
6467
install_k9s = var.operator_install_k9s
6568
install_kubectx = var.operator_install_kubectx
@@ -113,4 +116,4 @@ output "ssh_to_operator" {
113116
value = local.operator_enabled ? join(" ", concat(["ssh"],
114117
local.bastion_proxy_command, local.operator_ssh_args)
115118
) : null
116-
}
119+
}

modules/bastion/cloudinit.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ data "cloudinit_config" "bastion" {
3838
}
3939

4040
resource "null_resource" "await_cloudinit" {
41+
count = var.await_cloudinit ? 1 : 0
4142
connection {
4243
host = oci_core_instance.bastion.public_ip
4344
user = var.user
@@ -53,4 +54,4 @@ resource "null_resource" "await_cloudinit" {
5354
provisioner "remote-exec" {
5455
inline = ["cloud-init status --wait &> /dev/null"]
5556
}
56-
}
57+
}

modules/bastion/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ variable "compartment_id" { type = string }
66
variable "state_id" { type = string }
77

88
# Bastion
9+
variable "await_cloudinit" { type = string }
910
variable "assign_dns" { type = bool }
1011
variable "availability_domain" { type = string }
1112
variable "bastion_image_os_version" {type = string}
@@ -27,4 +28,4 @@ variable "user" { type = string }
2728
variable "defined_tags" { type = map(string) }
2829
variable "freeform_tags" { type = map(string) }
2930
variable "tag_namespace" { type = string }
30-
variable "use_defined_tags" { type = bool }
31+
variable "use_defined_tags" { type = bool }

modules/operator/cloudinit.tf

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,34 @@ data "cloudinit_config" "operator" {
102102
merge_type = local.default_cloud_init_merge_type
103103
}
104104

105+
106+
# OCI CLI installation from repo
107+
dynamic "part" {
108+
for_each = var.install_oci_cli_from_repo ? [1] : []
109+
content {
110+
content_type = "text/cloud-config"
111+
content = jsonencode({
112+
runcmd = [
113+
"curl -LO https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh",
114+
"su -c 'bash /install.sh --accept-all-defaults' - ${var.user}",
115+
]
116+
})
117+
filename = "20-oci_cli_from_repo.yml"
118+
merge_type = local.default_cloud_init_merge_type
119+
}
120+
}
121+
105122
# kubectl installation
106123
dynamic "part" {
107-
for_each = var.install_kubectl_from_repo ? [] : [1]
124+
for_each = var.install_kubectl_from_repo ? [1] : []
108125
content {
109126
content_type = "text/cloud-config"
110127
content = jsonencode({
111128
runcmd = [
112129
"CLI_ARCH='${local.arch_amd}'",
113130
"if [ \"$(uname -m)\" = ${local.arch_arm} ]; then CLI_ARCH='arm64'; fi",
114131
"curl -LO https://dl.k8s.io/release/${var.kubernetes_version}/bin/linux/$CLI_ARCH/kubectl",
115-
"install -o root -g root -m 0755 kubectl /usr/bin/kubectl"
132+
"install -o root -g root -m 0755 kubectl /usr/bin/kubectl",
116133
]
117134
})
118135
filename = "20-kubectl.yml"
@@ -137,6 +154,23 @@ data "cloudinit_config" "operator" {
137154
}
138155
}
139156

157+
# Helm installation from repo
158+
dynamic "part" {
159+
for_each = var.install_helm_from_repo ? [1] : []
160+
content {
161+
content_type = "text/cloud-config"
162+
content = jsonencode({
163+
runcmd = [
164+
"curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3",
165+
"chmod 700 get_helm.sh",
166+
"./get_helm.sh",
167+
]
168+
})
169+
filename = "20-helm_from_repo.yml"
170+
merge_type = local.default_cloud_init_merge_type
171+
}
172+
}
173+
140174
# Optional Helm installation bashrc
141175
dynamic "part" {
142176
for_each = var.install_helm ? [1] : []
@@ -166,7 +200,7 @@ data "cloudinit_config" "operator" {
166200
content_type = "text/cloud-config"
167201
content = jsonencode({
168202
runcmd = [
169-
"curl -LO https://github.com/derailed/k9s/releases/download/v0.27.2/k9s_Linux_amd64.tar.gz",
203+
"curl -LO https://github.com/derailed/k9s/releases/download/v0.40.5/k9s_Linux_amd64.tar.gz",
170204
"tar -xvzf k9s_Linux_amd64.tar.gz && mv ./k9s /usr/bin/k9s",
171205
]
172206
})
@@ -196,7 +230,7 @@ data "cloudinit_config" "operator" {
196230

197231
# stern installation
198232
dynamic "part" {
199-
for_each = var.install_kubectx ? [1] : []
233+
for_each = var.install_stern ? [1] : []
200234
content {
201235
content_type = "text/cloud-config"
202236
content = jsonencode({
@@ -311,6 +345,7 @@ data "cloudinit_config" "operator" {
311345
}
312346

313347
resource "null_resource" "await_cloudinit" {
348+
count = var.await_cloudinit ? 1 : 0
314349
connection {
315350
bastion_host = var.bastion_host
316351
bastion_user = var.bastion_user
@@ -329,4 +364,4 @@ resource "null_resource" "await_cloudinit" {
329364
provisioner "remote-exec" {
330365
inline = ["cloud-init status --wait &> /dev/null"]
331366
}
332-
}
367+
}

modules/operator/variables.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ variable "bastion_host" { type = string }
1010
variable "bastion_user" { type = string }
1111

1212
# Operator
13+
variable "await_cloudinit" { type = string }
1314
variable "assign_dns" { type = bool }
1415
variable "availability_domain" { type = string }
1516
variable "cloud_init" { type = list(map(string)) }
1617
variable "image_id" { type = string }
1718
variable "install_cilium" { type = bool }
19+
variable "install_oci_cli_from_repo" { type = bool }
1820
variable "install_helm" { type = bool }
21+
variable "install_helm_from_repo" { type = bool }
1922
variable "install_istioctl" { type = bool }
2023
variable "install_k9s" { type = bool }
2124
variable "install_kubectl_from_repo" {
@@ -45,4 +48,4 @@ variable "volume_kms_key_id" { type = string }
4548
variable "defined_tags" { type = map(string) }
4649
variable "freeform_tags" { type = map(string) }
4750
variable "tag_namespace" { type = string }
48-
variable "use_defined_tags" { type = bool }
51+
variable "use_defined_tags" { type = bool }

variables-bastion.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ variable "bastion_upgrade" {
8787
description = "Whether to upgrade bastion packages after provisioning."
8888
type = bool
8989
}
90+
91+
variable "bastion_await_cloudinit" {
92+
default = true
93+
description = "Whether to block until successful connection to bastion and completion of cloud-init."
94+
type = bool
95+
}

variables-operator.tf

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ variable "operator_install_helm" {
6565
type = bool
6666
}
6767

68+
variable "operator_install_helm_from_repo" {
69+
default = false
70+
description = "Whether to install Helm on the created operator host."
71+
type = bool
72+
}
73+
74+
variable "operator_install_oci_cli_from_repo" {
75+
default = false
76+
description = "Whether to install OCI from repo on the created operator host."
77+
type = bool
78+
}
79+
6880
variable "operator_install_istioctl" {
6981
default = false
7082
description = "Whether to install istioctl on the created operator host."
@@ -90,9 +102,9 @@ variable "operator_install_kubectx" {
90102
}
91103

92104
variable "operator_install_stern" {
93-
default = false
105+
default = false
94106
description = "Whether to install stern on the created operator host. NOTE: Provided only as a convenience and not supported by or sourced from Oracle - use at your own risk."
95-
type = bool
107+
type = bool
96108
}
97109

98110
variable "operator_shape" {
@@ -129,3 +141,9 @@ variable "operator_private_ip" {
129141
description = "The IP address of an existing operator host. Ignored when create_operator = true."
130142
type = string
131143
}
144+
145+
variable "operator_await_cloudinit" {
146+
default = true
147+
description = "Whether to block until successful connection to operator and completion of cloud-init."
148+
type = bool
149+
}

0 commit comments

Comments
 (0)