From a57225097daffdada9f92fd90e1c4f3333c83435 Mon Sep 17 00:00:00 2001 From: Thomas Tanaka Date: Mon, 18 Sep 2023 15:38:42 -0700 Subject: [PATCH 1/3] Enable extra disk to be assigned to a compute Signed-off-by: Thomas Tanaka --- modules/oci-ocne-compute/main.tf | 31 +++++++++++++++++++++++++++ modules/oci-ocne-compute/variables.tf | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/modules/oci-ocne-compute/main.tf b/modules/oci-ocne-compute/main.tf index bf54a70..e5ad996 100644 --- a/modules/oci-ocne-compute/main.tf +++ b/modules/oci-ocne-compute/main.tf @@ -95,3 +95,34 @@ resource "null_resource" "assign_vnics" { ] } } + +resource "oci_core_volume" "volume_resource" { + count = var.attach_extra_disk ? var.instance_count : 0 + availability_domain = var.availability_domain_id + compartment_id = var.compartment_id + display_name = format("${var.prefix}-%03d", count.index + 1) + size_in_gbs = 50 +} + +resource "oci_core_volume_attachment" "volume_attachment" { + depends_on = [oci_core_instance.instance, oci_core_volume.volume_resource] + attachment_type = "iscsi" + count = var.attach_extra_disk ? var.instance_count : 0 + instance_id = oci_core_instance.instance[count.index].id + volume_id = oci_core_volume.volume_resource[count.index].id + connection { + agent = false + timeout = "30m" + host = oci_core_instance.instance[count.index].private_ip + user = "opc" + private_key = file(var.ssh_private_key_path) + } + + provisioner "remote-exec" { + inline = [ + "sudo iscsiadm -m node -o new -T ${self.iqn} -p ${self.ipv4}:${self.port}", + "sudo iscsiadm -m node -o update -T ${self.iqn} -n node.startup -v automatic", + "sudo iscsiadm -m node -T ${self.iqn} -p ${self.ipv4}:${self.port} -l", + ] + } +} diff --git a/modules/oci-ocne-compute/variables.tf b/modules/oci-ocne-compute/variables.tf index a412eac..122a321 100644 --- a/modules/oci-ocne-compute/variables.tf +++ b/modules/oci-ocne-compute/variables.tf @@ -44,6 +44,12 @@ variable "attach_secondary_vnic" { default = false } +variable "attach_extra_disk" { + type = bool + description = "If set to true, allocate a secondary disk" + default = false +} + // Compute instance specific variables variable "ssh_public_key_path" { type = string From a8ea82312a1ba78c403b91a5c01e8ab3832eea7e Mon Sep 17 00:00:00 2001 From: Thomas Tanaka Date: Tue, 19 Sep 2023 15:43:33 -0700 Subject: [PATCH 2/3] Review suggestions Signed-off-by: Thomas Tanaka --- modules/oci-ocne-compute/main.tf | 8 +++++--- modules/oci-ocne-compute/variables.tf | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/oci-ocne-compute/main.tf b/modules/oci-ocne-compute/main.tf index e5ad996..b227ca9 100644 --- a/modules/oci-ocne-compute/main.tf +++ b/modules/oci-ocne-compute/main.tf @@ -97,17 +97,19 @@ resource "null_resource" "assign_vnics" { } resource "oci_core_volume" "volume_resource" { - count = var.attach_extra_disk ? var.instance_count : 0 + # volume size should be between 50 GB and 32768 GB + count = (var.extra_disk_size_in_gbs >= 50) ? var.instance_count : 0 availability_domain = var.availability_domain_id compartment_id = var.compartment_id display_name = format("${var.prefix}-%03d", count.index + 1) - size_in_gbs = 50 + size_in_gbs = var.extra_disk_size_in_gbs } resource "oci_core_volume_attachment" "volume_attachment" { depends_on = [oci_core_instance.instance, oci_core_volume.volume_resource] attachment_type = "iscsi" - count = var.attach_extra_disk ? var.instance_count : 0 + # volume size should be between 50 GB and 32768 GB + count = (var.extra_disk_size_in_gbs >= 50) ? var.instance_count : 0 instance_id = oci_core_instance.instance[count.index].id volume_id = oci_core_volume.volume_resource[count.index].id connection { diff --git a/modules/oci-ocne-compute/variables.tf b/modules/oci-ocne-compute/variables.tf index 122a321..7a5f056 100644 --- a/modules/oci-ocne-compute/variables.tf +++ b/modules/oci-ocne-compute/variables.tf @@ -44,10 +44,10 @@ variable "attach_secondary_vnic" { default = false } -variable "attach_extra_disk" { - type = bool - description = "If set to true, allocate a secondary disk" - default = false +variable "extra_disk_size_in_gbs" { + type = number + description = "If >= 50, will provision a secondary disk drive, but note that this number needs to be between 50 GB and 32768 GB (OCI volume size)" + default = 0 } // Compute instance specific variables From 319f4992207254dadccf03365a8494ac4a9aecd7 Mon Sep 17 00:00:00 2001 From: Thomas Tanaka Date: Tue, 26 Sep 2023 15:30:21 -0700 Subject: [PATCH 3/3] Review comments 2 Signed-off-by: Thomas Tanaka --- main.tf | 1 + modules/terraform-oci-ocne-infrastructure/main.tf | 3 +++ modules/terraform-oci-ocne-infrastructure/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/main.tf b/main.tf index ca5e09e..9970708 100644 --- a/main.tf +++ b/main.tf @@ -95,6 +95,7 @@ module "infrastructure" { compute_user = var.compute_user freeform_tags = var.freeform_tags virtual_ip = var.virtual_ip + extra_disk_size_in_gbs = var.extra_disk_size_in_gbs } module "vault" { diff --git a/modules/terraform-oci-ocne-infrastructure/main.tf b/modules/terraform-oci-ocne-infrastructure/main.tf index cd44872..69a3f5c 100644 --- a/modules/terraform-oci-ocne-infrastructure/main.tf +++ b/modules/terraform-oci-ocne-infrastructure/main.tf @@ -46,6 +46,7 @@ module "api-server-compute" { compute_user = var.compute_user freeform_tags = var.freeform_tags attach_secondary_vnic = var.standalone_api_server ? false : var.virtual_ip + extra_disk_size_in_gbs = 0 } module "control-plane-compute" { @@ -69,6 +70,7 @@ module "control-plane-compute" { compute_user = var.compute_user freeform_tags = var.freeform_tags attach_secondary_vnic = var.standalone_api_server ? var.virtual_ip : false + extra_disk_size_in_gbs = 0 } module "worker-compute" { @@ -91,6 +93,7 @@ module "worker-compute" { bastion_private_key_path = var.bastion_private_key_path compute_user = var.compute_user freeform_tags = var.freeform_tags + extra_disk_size_in_gbs = var.extra_disk_size_in_gbs } resource "null_resource" "copy_apiserver_ssh_key" { diff --git a/modules/terraform-oci-ocne-infrastructure/variables.tf b/modules/terraform-oci-ocne-infrastructure/variables.tf index 0e8ed9e..348db22 100644 --- a/modules/terraform-oci-ocne-infrastructure/variables.tf +++ b/modules/terraform-oci-ocne-infrastructure/variables.tf @@ -160,3 +160,9 @@ variable "virtual_ip" { description = "Setup Kubernetes API server endpoint on a virtual IP address representing all the Kubernetes control plane nodes" default = false } + +variable "extra_disk_size_in_gbs" { + type = number + description = "If >= 50, will provision a secondary disk drive, but note that this number needs to be between 50 GB and 32768 GB (OCI volume size)" + default = 0 +} diff --git a/variables.tf b/variables.tf index 24ed110..e284783 100644 --- a/variables.tf +++ b/variables.tf @@ -342,3 +342,9 @@ variable "config_file_path" { description = "The path to the OCNE configuration file - https://docs.oracle.com/en/operating-systems/olcne/1.7/olcnectl/config.html" default = "" } + +variable "extra_disk_size_in_gbs" { + type = number + description = "If >= 50, will provision a secondary disk drive, but note that this number needs to be between 50 GB and 32768 GB (OCI volume size)" + default = 0 +}