feat: allow OCI foundation without compute instances

This commit is contained in:
juvenal.diaz 2026-10-26 10:35:20 -06:00
parent ce9aead7a6
commit 04a8e99695
5 changed files with 29 additions and 12 deletions

View File

@ -29,6 +29,11 @@ the image and availability-domain variables for both VMs. Use
`LAB_OCI_CREATE_COMPARTMENT=false` with `LAB_OCI_COMPARTMENT_ID` when the
tenancy policy does not allow creating child compartments.
To test a complete compartment/network foundation without consuming another
Always Free compute slot, set `LAB_OCI_COMPUTE_ENABLED=false`. Edge/email
subnets and security groups are still created; the VM resources are deferred
until the variable is set back to `true`.
After a successful apply, Jeannie persists the discovered edge IP and uses it
as the next-run edge target instead of the static inventory value. To update
DuckDNS automatically when OCI assigns a replacement public IP, provide the

View File

@ -303,12 +303,12 @@ resource "oci_core_network_security_group_security_rule" "email_monitoring" {
}
data "oci_core_instance" "existing_edge" {
count = var.enabled && var.edge_enabled && trimspace(var.edge_existing_instance_id) != "" ? 1 : 0
count = var.enabled && var.compute_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 && trimspace(var.edge_existing_instance_id) == "" ? 1 : 0
count = var.enabled && var.compute_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
@ -333,7 +333,7 @@ resource "oci_core_instance" "edge" {
}
resource "oci_core_instance" "email" {
count = var.enabled && var.email_enabled ? 1 : 0
count = var.enabled && var.compute_enabled && var.email_enabled ? 1 : 0
availability_domain = var.email_availability_domain
compartment_id = local.email_compartment_id
display_name = var.email_display_name

View File

@ -140,6 +140,12 @@ variable "email_enabled" {
default = true
}
variable "compute_enabled" {
description = "Create the edge and email compute instances. Set false to test compartments and networking without consuming Always Free VM capacity."
type = bool
default = true
}
variable "edge_availability_domain" {
type = string
default = ""
@ -242,9 +248,9 @@ check "foundation_inputs" {
(!var.email_enabled || var.email_create_compartment || trimspace(var.email_compartment_id) != "") &&
((trimspace(var.existing_vcn_id) == "" && trimspace(var.existing_public_subnet_id) == "") || (trimspace(var.existing_vcn_id) != "" && trimspace(var.existing_public_subnet_id) != "")) &&
trimspace(var.admin_cidr) != "" &&
(!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) != ""
(!var.compute_enabled || !var.edge_enabled || trimspace(var.edge_existing_instance_id) != "" || (trimspace(var.edge_availability_domain) != "" && trimspace(var.edge_image_id) != "")) &&
(!var.compute_enabled || !var.email_enabled || (trimspace(var.email_availability_domain) != "" && trimspace(var.email_image_id) != "")) &&
(!var.compute_enabled || trimspace(var.ssh_public_key) != "")
)
error_message = "When OCI foundation is enabled, region, tenancy_id, admin_cidr, SSH key, and image/availability-domain inputs for each enabled VM are required."
}
@ -263,11 +269,11 @@ check "foundation_inputs" {
assert {
condition = !var.enabled || (
(!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 && 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
(!var.compute_enabled || !var.edge_enabled || trimspace(var.edge_existing_instance_id) != "" || var.edge_shape == "VM.Standard.E2.1.Micro") &&
(!var.compute_enabled || !var.email_enabled || var.email_shape == "VM.Standard.E2.1.Micro") &&
(!var.compute_enabled || (var.edge_enabled && trimspace(var.edge_existing_instance_id) == "" ? var.edge_ocpus : 0) + (var.email_enabled ? var.email_ocpus : 0) <= 2) &&
(!var.compute_enabled || (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.compute_enabled || (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."
}

View File

@ -3594,7 +3594,7 @@ email_vm_manage() {
oci_foundation_config_names=(
LAB_OCI_FOUNDATION_ENABLED LAB_OCI_REGION LAB_OCI_TENANCY_ID LAB_OCI_ADMIN_CIDR
LAB_OCI_SSH_PUBLIC_KEY LAB_OCI_CREATE_COMPARTMENT LAB_OCI_COMPARTMENT_ID
LAB_OCI_EDGE_ENABLED LAB_OCI_EMAIL_ENABLED LAB_OCI_EDGE_EXISTING_INSTANCE_ID
LAB_OCI_EDGE_ENABLED LAB_OCI_EMAIL_ENABLED LAB_OCI_COMPUTE_ENABLED LAB_OCI_EDGE_EXISTING_INSTANCE_ID
LAB_OCI_EXISTING_VCN_ID LAB_OCI_EXISTING_PUBLIC_SUBNET_ID LAB_OCI_EXISTING_EMAIL_SUBNET_ID
LAB_OCI_EMAIL_CREATE_COMPARTMENT LAB_OCI_EMAIL_COMPARTMENT_ID LAB_OCI_EMAIL_COMPARTMENT_NAME
LAB_OCI_EMAIL_SUBNET_CIDR LAB_OCI_EDGE_AVAILABILITY_DOMAIN LAB_OCI_EMAIL_AVAILABILITY_DOMAIN
@ -3635,6 +3635,9 @@ oci_foundation_save_config() {
oci_foundation_reconcile_existing() {
local oci_bin="" output_file status
if disabled_value "${LAB_OCI_COMPUTE_ENABLED:-true}"; then
return 0
fi
if command -v oci >/dev/null 2>&1; then
oci_bin="$(command -v oci)"
elif [[ -x "${HOME}/.local/share/homelab/venvs/oci-cli/bin/oci" ]]; then
@ -3751,6 +3754,7 @@ oci_foundation_manage() {
# A previous invocation in a long-lived API process must not retain stale
# TF_VAR values after the persisted OCI inputs change.
unset TF_VAR_enabled TF_VAR_region TF_VAR_tenancy_id TF_VAR_admin_cidr
unset TF_VAR_compute_enabled
unset TF_VAR_edge_availability_domain TF_VAR_email_availability_domain
unset TF_VAR_existing_vcn_id TF_VAR_existing_public_subnet_id TF_VAR_existing_email_subnet_id
export_oci_foundation_tf_vars
@ -3772,6 +3776,7 @@ oci_foundation_manage() {
fi
oci_foundation_reconcile_existing
unset TF_VAR_enabled TF_VAR_region TF_VAR_tenancy_id TF_VAR_admin_cidr
unset TF_VAR_compute_enabled
unset TF_VAR_edge_availability_domain TF_VAR_email_availability_domain
unset TF_VAR_existing_vcn_id TF_VAR_existing_public_subnet_id TF_VAR_existing_email_subnet_id
export_oci_foundation_tf_vars

View File

@ -356,6 +356,7 @@ export_oci_foundation_tf_vars() {
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_compute_enabled "${LAB_OCI_COMPUTE_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:-}}"
export_if_unset TF_VAR_edge_image_id "${LAB_OCI_EDGE_IMAGE_ID:-}"