diff --git a/main.tf b/main.tf index f7de680..ff1bfa5 100644 --- a/main.tf +++ b/main.tf @@ -119,6 +119,8 @@ module "oke_node_pools" { node_pool_node_shape_config_ocpus = each.value.node_pool_node_shape_config_ocpus node_pool_node_shape_config_memory_in_gbs = each.value.node_pool_node_shape_config_memory_in_gbs existent_oke_nodepool_id_for_autoscaler = each.value.existent_oke_nodepool_id_for_autoscaler + node_pool_oke_init_params = each.value.node_pool_oke_init_params + node_pool_cloud_init_parts = each.value.node_pool_cloud_init_parts public_ssh_key = local.workers_public_ssh_key image_operating_system = each.value.image_operating_system image_operating_system_version = each.value.image_operating_system_version @@ -148,6 +150,8 @@ locals { node_pool_node_shape_config_memory_in_gbs = var.node_pool_instance_shape_1.memory node_pool_boot_volume_size_in_gbs = var.node_pool_boot_volume_size_in_gbs_1 existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler_1 + node_pool_oke_init_params = var.node_pool_oke_init_params_1 + node_pool_cloud_init_parts = var.node_pool_cloud_init_parts_1 node_pool_alternative_subnet = null image_operating_system = var.image_operating_system_1 image_operating_system_version = var.image_operating_system_version_1 diff --git a/modules/oke-node-pool/datasources.tf b/modules/oke-node-pool/datasources.tf index 9a8de2a..e471763 100644 --- a/modules/oke-node-pool/datasources.tf +++ b/modules/oke-node-pool/datasources.tf @@ -27,4 +27,28 @@ data "oci_identity_availability_domain" "specfic" { ad_number = var.node_pool_shape_specific_ad count = (var.node_pool_shape_specific_ad > 0) ? 1 : 0 +} + +# Prepare Cloud Unit for Node Pool nodes +data "cloudinit_config" "nodes" { + gzip = true + base64_encode = true + + part { + content_type = "text/x-shellscript" + content = </var/run/oke-init.sh +bash /var/run/oke-init.sh ${var.node_pool_oke_init_params} +EOF + } + + dynamic "part" { + for_each = var.node_pool_cloud_init_parts + content { + content_type = part.value["content_type"] + content = part.value["content"] + filename = part.value["filename"] + } + } } \ No newline at end of file diff --git a/modules/oke-node-pool/main.tf b/modules/oke-node-pool/main.tf index 9239294..b632280 100644 --- a/modules/oke-node-pool/main.tf +++ b/modules/oke-node-pool/main.tf @@ -53,7 +53,16 @@ resource "oci_containerengine_node_pool" "oke_node_pool" { # eviction_grace_duration = "PT1H" # is_force_delete_after_grace_duration = false # } - # node_metadata = {} + node_metadata = { + user_data = anytrue([var.node_pool_oke_init_params != "", var.node_pool_cloud_init_parts != []]) ? data.cloudinit_config.nodes.rendered : null + } + # dynamic "node_metadata" { + # for_each = alltrue([var.node_pool_oke_init_params != "", var.node_pool_cloud_init_parts != []]) ? [1] : [] + + # content { + # user_data = data.cloudinit_config.nodes.rendered + # } + # } initial_node_labels { key = "name" diff --git a/modules/oke-node-pool/variables.tf b/modules/oke-node-pool/variables.tf index b6acf20..1f87c93 100644 --- a/modules/oke-node-pool/variables.tf +++ b/modules/oke-node-pool/variables.tf @@ -85,6 +85,20 @@ variable "node_pool_boot_volume_size_in_gbs" { default = "50" description = "Specify a custom boot volume size (in GB)" } +variable "node_pool_oke_init_params" { + type = string + default = "" + description = "OKE Init params" +} +variable "node_pool_cloud_init_parts" { + type = list(object({ + content_type = string + content = string + filename = string + })) + default = [] + description = "Node Pool nodes Cloud init parts" +} variable "public_ssh_key" { default = "" description = "In order to access your private nodes with a public SSH key you will need to set up a bastion host (a.k.a. jump box). If using public nodes, bastion is not needed. Left blank to not import keys."