From 5a25c3a8560ee3035022ddcb0fd542656adb91ed Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Fri, 23 Oct 2026 20:22:49 -0600 Subject: [PATCH] feat: adopt existing OCI edge instance --- bootstrap/oci/main.tf | 7 ++++++- bootstrap/oci/outputs.tf | 4 ++-- bootstrap/oci/variables.tf | 16 +++++++++++----- lib/jeannie/env.sh | 1 + 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bootstrap/oci/main.tf b/bootstrap/oci/main.tf index d423dbd..051aeed 100644 --- a/bootstrap/oci/main.tf +++ b/bootstrap/oci/main.tf @@ -226,8 +226,13 @@ resource "oci_core_network_security_group_security_rule" "email_imaps" { } } +data "oci_core_instance" "existing_edge" { + count = var.enabled && var.edge_enabled && trimspace(var.edge_existing_instance_id) != "" ? 1 : 0 + instance_id = var.edge_existing_instance_id +} + resource "oci_core_instance" "edge" { - count = var.enabled && var.edge_enabled ? 1 : 0 + count = var.enabled && var.edge_enabled && trimspace(var.edge_existing_instance_id) == "" ? 1 : 0 availability_domain = var.edge_availability_domain compartment_id = local.target_compartment_id display_name = var.edge_display_name diff --git a/bootstrap/oci/outputs.tf b/bootstrap/oci/outputs.tf index 1c0d627..df5645a 100644 --- a/bootstrap/oci/outputs.tf +++ b/bootstrap/oci/outputs.tf @@ -2,8 +2,8 @@ output "compartment_id" { value = local.target_compartment_id } output "vcn_id" { value = try(oci_core_vcn.homelab[0].id, null) } output "public_subnet_id" { value = try(oci_core_subnet.public[0].id, null) } output "private_subnet_id" { value = try(oci_core_subnet.private[0].id, null) } -output "edge_instance_id" { value = try(oci_core_instance.edge[0].id, null) } -output "edge_public_ip" { value = try(oci_core_instance.edge[0].public_ip, null) } +output "edge_instance_id" { value = try(oci_core_instance.edge[0].id, data.oci_core_instance.existing_edge[0].id, null) } +output "edge_public_ip" { value = try(oci_core_instance.edge[0].public_ip, data.oci_core_instance.existing_edge[0].public_ip, null) } output "email_instance_id" { value = try(oci_core_instance.email[0].id, null) } output "email_public_ip" { value = try(oci_core_instance.email[0].public_ip, null) } output "next_steps" { diff --git a/bootstrap/oci/variables.tf b/bootstrap/oci/variables.tf index 02753b7..2306db8 100644 --- a/bootstrap/oci/variables.tf +++ b/bootstrap/oci/variables.tf @@ -78,6 +78,12 @@ variable "edge_enabled" { default = true } +variable "edge_existing_instance_id" { + description = "Existing OCI edge instance OCID to adopt read-only instead of creating a new edge VM." + type = string + default = "" +} + variable "email_enabled" { type = bool default = true @@ -183,7 +189,7 @@ check "foundation_inputs" { trimspace(var.tenancy_id) != "" && (var.create_compartment || trimspace(var.compartment_id) != "") && trimspace(var.admin_cidr) != "" && - (!var.edge_enabled || (trimspace(var.edge_availability_domain) != "" && trimspace(var.edge_image_id) != "")) && + (!var.edge_enabled || trimspace(var.edge_existing_instance_id) != "" || (trimspace(var.edge_availability_domain) != "" && trimspace(var.edge_image_id) != "")) && (!var.email_enabled || (trimspace(var.email_availability_domain) != "" && trimspace(var.email_image_id) != "")) && trimspace(var.ssh_public_key) != "" ) @@ -204,11 +210,11 @@ check "foundation_inputs" { assert { condition = !var.enabled || ( - (!var.edge_enabled || var.edge_shape == "VM.Standard.E2.1.Micro") && + (!var.edge_enabled || trimspace(var.edge_existing_instance_id) != "" || var.edge_shape == "VM.Standard.E2.1.Micro") && (!var.email_enabled || var.email_shape == "VM.Standard.E2.1.Micro") && - (var.edge_enabled ? var.edge_ocpus : 0) + (var.email_enabled ? var.email_ocpus : 0) <= 2 && - (var.edge_enabled ? var.edge_memory_in_gbs : 0) + (var.email_enabled ? var.email_memory_in_gbs : 0) <= 2 && - (var.edge_enabled ? var.edge_boot_volume_size_in_gbs : 0) + (var.email_enabled ? var.email_boot_volume_size_in_gbs : 0) <= 200 + (var.edge_enabled && trimspace(var.edge_existing_instance_id) == "" ? var.edge_ocpus : 0) + (var.email_enabled ? var.email_ocpus : 0) <= 2 && + (var.edge_enabled && trimspace(var.edge_existing_instance_id) == "" ? var.edge_memory_in_gbs : 0) + (var.email_enabled ? var.email_memory_in_gbs : 0) <= 2 && + (var.edge_enabled && trimspace(var.edge_existing_instance_id) == "" ? var.edge_boot_volume_size_in_gbs : 0) + (var.email_enabled ? var.email_boot_volume_size_in_gbs : 0) <= 200 ) error_message = "The foundation is restricted to OCI Always Free VM.Standard.E2.1.Micro instances, at most 2 total OCPUs, 2 GB total memory, and 200 GB total boot volumes." } diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index 40a8dca..eaf5772 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -343,6 +343,7 @@ export_oci_foundation_tf_vars() { export_if_unset TF_VAR_admin_cidr "${LAB_OCI_ADMIN_CIDR:-}" export_if_unset TF_VAR_open_mail_ports "${LAB_OCI_OPEN_MAIL_PORTS:-}" export_if_unset TF_VAR_edge_enabled "${LAB_OCI_EDGE_ENABLED:-}" + export_if_unset TF_VAR_edge_existing_instance_id "${LAB_OCI_EDGE_EXISTING_INSTANCE_ID:-}" export_if_unset TF_VAR_email_enabled "${LAB_OCI_EMAIL_ENABLED:-}" export_if_unset TF_VAR_edge_availability_domain "${LAB_OCI_EDGE_AVAILABILITY_DOMAIN:-}" export_if_unset TF_VAR_email_availability_domain "${LAB_OCI_EMAIL_AVAILABILITY_DOMAIN:-${LAB_EMAIL_AVAILABILITY_DOMAIN:-}}"