Skip to content

Enable extra disk to be assigned to a compute #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
33 changes: 33 additions & 0 deletions modules/oci-ocne-compute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,36 @@ resource "null_resource" "assign_vnics" {
]
}
}

resource "oci_core_volume" "volume_resource" {
# 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 = 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"
# 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 {
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",
]
}
}
6 changes: 6 additions & 0 deletions modules/oci-ocne-compute/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ variable "attach_secondary_vnic" {
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
variable "ssh_public_key_path" {
type = string
Expand Down
3 changes: 3 additions & 0 deletions modules/terraform-oci-ocne-infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand All @@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions modules/terraform-oci-ocne-infrastructure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}