feat: add opt-in OCI email VM pipeline
This commit is contained in:
parent
05245a8bba
commit
c6602fc237
|
|
@ -0,0 +1,32 @@
|
|||
# OCI email learning VM
|
||||
|
||||
This is an independent, opt-in OpenTofu stack. It creates one OCI compute VM
|
||||
inside an existing compartment and subnet; it does not install a mail server,
|
||||
change DNS, or open SMTP ports. Keep `enabled=false` until the OCI image,
|
||||
network, and SSH inputs are known.
|
||||
|
||||
The default `VM.Standard.A1.Flex` shape is suitable for an ARM64 Ampere image
|
||||
and may fit OCI Always Free capacity. Capacity is not guaranteed, so override
|
||||
the shape and image when needed.
|
||||
|
||||
Example on the Debian pipeline host:
|
||||
|
||||
```sh
|
||||
export LAB_EMAIL_VM_ENABLED=true
|
||||
export LAB_EMAIL_OCI_REGION=us-phoenix-1
|
||||
export LAB_EMAIL_COMPARTMENT_ID=ocid1.compartment...
|
||||
export LAB_EMAIL_AVAILABILITY_DOMAIN='...'
|
||||
export LAB_EMAIL_SUBNET_ID=ocid1.subnet...
|
||||
export LAB_EMAIL_IMAGE_ID=ocid1.image...
|
||||
export LAB_EMAIL_SSH_PUBLIC_KEY="$(cat ~/.ssh/id_ed25519.pub)"
|
||||
export LAB_EMAIL_DOMAIN=example.org
|
||||
# Optional existing NSGs, as a JSON list. Do not open mail ingress yet.
|
||||
export LAB_EMAIL_NSG_IDS='["ocid1.networksecuritygroup..."]'
|
||||
./jeannie email-vm plan
|
||||
./jeannie email-vm apply
|
||||
```
|
||||
|
||||
The provider reads OCI credentials from the normal OCI CLI configuration
|
||||
(`~/.oci/config`) and never stores private keys in this repository. `destroy`
|
||||
requires `--yes`. The stack is intentionally separate from `platform`, `apps`,
|
||||
and `up`, so mail experiments cannot modify the Kubernetes cluster.
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
resource "oci_core_instance" "email" {
|
||||
count = var.enabled ? 1 : 0
|
||||
|
||||
availability_domain = var.availability_domain
|
||||
compartment_id = var.compartment_id
|
||||
display_name = var.display_name
|
||||
shape = var.shape
|
||||
|
||||
shape_config {
|
||||
ocpus = var.ocpus
|
||||
memory_in_gbs = var.memory_in_gbs
|
||||
}
|
||||
|
||||
source_details {
|
||||
source_type = "image"
|
||||
source_id = var.image_id
|
||||
boot_volume_size_in_gbs = var.boot_volume_size_in_gbs
|
||||
}
|
||||
|
||||
create_vnic_details {
|
||||
subnet_id = var.subnet_id
|
||||
assign_public_ip = var.assign_public_ip
|
||||
hostname_label = var.hostname_label
|
||||
skip_source_dest_check = false
|
||||
nsg_ids = var.nsg_ids
|
||||
}
|
||||
|
||||
metadata = {
|
||||
ssh_authorized_keys = var.ssh_public_key
|
||||
}
|
||||
|
||||
freeform_tags = merge(var.freeform_tags, {
|
||||
managed_by = "jeannie"
|
||||
purpose = "email-learning"
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
output "instance_id" {
|
||||
value = try(oci_core_instance.email[0].id, null)
|
||||
}
|
||||
|
||||
output "private_ip" {
|
||||
value = try(oci_core_instance.email[0].private_ip, null)
|
||||
}
|
||||
|
||||
output "public_ip" {
|
||||
value = try(oci_core_instance.email[0].public_ip, null)
|
||||
}
|
||||
|
||||
output "domain" {
|
||||
value = var.domain
|
||||
}
|
||||
|
||||
output "ssh_command" {
|
||||
value = try("ssh opc@${oci_core_instance.email[0].public_ip}", null)
|
||||
}
|
||||
|
||||
output "mail_prerequisites" {
|
||||
value = [
|
||||
"Use a reserved public IP before production mail.",
|
||||
"Request OCI reverse DNS/PTR for the public IP.",
|
||||
"Request OCI SMTP port 25 access; it is restricted by default for newer tenancies.",
|
||||
"Create SPF, DKIM, DMARC, MX, and A/AAAA records for the chosen domain.",
|
||||
"Open mail ports only in an explicit NSG/security-list change after DNS and hardening are ready.",
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
variable "enabled" {
|
||||
description = "Create the learning email VM. Keep false until all OCI inputs are set."
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "OCI region, normally supplied by TF_VAR_email_region or OCI_REGION."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "oci_config_profile" {
|
||||
description = "OCI CLI config profile used by the provider."
|
||||
type = string
|
||||
default = "DEFAULT"
|
||||
}
|
||||
|
||||
variable "compartment_id" {
|
||||
description = "OCI compartment OCID for the VM."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "availability_domain" {
|
||||
description = "OCI availability domain name."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "subnet_id" {
|
||||
description = "Existing public subnet OCID for the VM VNIC."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "image_id" {
|
||||
description = "ARM64 or x86 image OCID compatible with the selected shape."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "ssh_public_key" {
|
||||
description = "Public SSH key installed in the VM."
|
||||
type = string
|
||||
default = ""
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "shape" {
|
||||
description = "OCI shape. VM.Standard.A1.Flex is free-tier eligible when capacity is available."
|
||||
type = string
|
||||
default = "VM.Standard.A1.Flex"
|
||||
}
|
||||
|
||||
variable "ocpus" {
|
||||
description = "Number of OCPUs. Keep within the free-tier allowance."
|
||||
type = number
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "memory_in_gbs" {
|
||||
description = "Memory in GB. Keep within the free-tier allowance."
|
||||
type = number
|
||||
default = 6
|
||||
}
|
||||
|
||||
variable "boot_volume_size_in_gbs" {
|
||||
description = "Boot volume size in GB."
|
||||
type = number
|
||||
default = 50
|
||||
}
|
||||
|
||||
variable "display_name" {
|
||||
type = string
|
||||
default = "homelab-mail"
|
||||
}
|
||||
|
||||
variable "hostname_label" {
|
||||
type = string
|
||||
default = "homelab-mail"
|
||||
}
|
||||
|
||||
variable "assign_public_ip" {
|
||||
description = "Assign an ephemeral public IP to the VM VNIC. Reserve a static IP before production mail use."
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "nsg_ids" {
|
||||
description = "Existing OCI Network Security Group OCIDs. Keep mail ingress closed until DNS/PTR are ready."
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "domain" {
|
||||
description = "Future mail domain, recorded in outputs only until explicitly configured."
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "freeform_tags" {
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
locals {
|
||||
required_inputs = {
|
||||
compartment_id = var.compartment_id
|
||||
availability_domain = var.availability_domain
|
||||
subnet_id = var.subnet_id
|
||||
image_id = var.image_id
|
||||
ssh_public_key = var.ssh_public_key
|
||||
region = var.region
|
||||
}
|
||||
}
|
||||
|
||||
check "email_vm_inputs" {
|
||||
assert {
|
||||
condition = !var.enabled || alltrue([for value in values(local.required_inputs) : trimspace(value) != ""])
|
||||
error_message = "When email VM creation is enabled, region, compartment_id, availability_domain, subnet_id, image_id, and ssh_public_key are required."
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = var.ocpus > 0 && var.memory_in_gbs > 0 && var.boot_volume_size_in_gbs >= 50
|
||||
error_message = "ocpus and memory_in_gbs must be positive and boot_volume_size_in_gbs must be at least 50."
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
terraform {
|
||||
required_version = ">= 1.5.0"
|
||||
|
||||
required_providers {
|
||||
oci = {
|
||||
source = "oracle/oci"
|
||||
version = "~> 6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "oci" {
|
||||
region = var.region
|
||||
config_file_profile = var.oci_config_profile
|
||||
}
|
||||
|
|
@ -63,6 +63,7 @@ var allowedCommands = map[string]bool{
|
|||
"state-backup": true, "fix-debian-docker-root": true,
|
||||
"state": true,
|
||||
"pimox": true,
|
||||
"email-vm": true,
|
||||
"secrets-init": true, "secrets-check": true, "tailnet-policy-check": true,
|
||||
"secrets": true,
|
||||
"ai-index": true, "ai-check": true, "ask": true, "ai-evals": true,
|
||||
|
|
|
|||
|
|
@ -141,3 +141,9 @@ func TestPimoxCommandIsRemotelyEnabled(t *testing.T) {
|
|||
t.Fatal("pimox must be exposed through the remote API")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailVMCommandIsRemotelyEnabled(t *testing.T) {
|
||||
if !allowedCommands["email-vm"] {
|
||||
t.Fatal("email-vm must be exposed through the remote API")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
jeannie
4
jeannie
|
|
@ -122,6 +122,7 @@ Observability And GitOps
|
|||
platform [all|calico|metrics|dns|metallb|ingress|storage|argocd|security|logging|monitoring|tools]
|
||||
Deploy one platform component or the full platform stack.
|
||||
edge Deploy/check the OCI edge stack only.
|
||||
email-vm {status|plan|apply|destroy --yes} Manage the independent OCI email learning VM.
|
||||
edge-cache-flush Clear Nginx, Varnish, and Squid edge caches.
|
||||
promote {plan|validate|rollback APP} Run canary promotion gates and rollback plan.
|
||||
cert-check Check public DNS, TLS, and edge URL health.
|
||||
|
|
@ -287,6 +288,9 @@ case "${1:-}" in
|
|||
run_step "Edge OpenTofu apply" edge_apply
|
||||
echo "Log: ${JEANNIE_LOG_FILE}"
|
||||
;;
|
||||
email-vm)
|
||||
email_vm_manage "${@:2}"
|
||||
;;
|
||||
edge-cache-flush)
|
||||
edge_flush_caches
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -3286,6 +3286,47 @@ pimox_oob() {
|
|||
"${REPO_ROOT}/scripts/pimox-oob" "$@"
|
||||
}
|
||||
|
||||
email_vm_manage() {
|
||||
require_debian_server "email-vm"
|
||||
export_email_vm_tf_vars
|
||||
local action="${1:-status}"
|
||||
shift || true
|
||||
local stack="${REPO_ROOT}/bootstrap/email"
|
||||
|
||||
case "${action}" in
|
||||
status)
|
||||
tofu -chdir="${stack}" show -no-color 2>/dev/null || echo "OCI email VM has no state yet."
|
||||
;;
|
||||
plan|apply)
|
||||
if [[ "${TF_VAR_enabled:-false}" != "true" ]]; then
|
||||
echo "OCI email VM is disabled. Set LAB_EMAIL_VM_ENABLED=true and the required LAB_EMAIL_* inputs first." >&2
|
||||
return 2
|
||||
fi
|
||||
tofu -chdir="${stack}" init
|
||||
if [[ "${action}" == "plan" ]]; then
|
||||
tofu -chdir="${stack}" plan "$@"
|
||||
else
|
||||
record_change_journal "email-vm" "${action}" "$@"
|
||||
tofu -chdir="${stack}" apply "$@" -auto-approve
|
||||
fi
|
||||
;;
|
||||
destroy)
|
||||
if [[ "${1:-}" != "--yes" ]]; then
|
||||
echo "Refusing to destroy the OCI email VM without --yes." >&2
|
||||
return 2
|
||||
fi
|
||||
shift
|
||||
record_change_journal "email-vm" destroy "$@"
|
||||
tofu -chdir="${stack}" init
|
||||
tofu -chdir="${stack}" destroy "$@" -auto-approve
|
||||
;;
|
||||
*)
|
||||
echo "Usage: ./jeannie email-vm {status|plan|apply|destroy --yes}" >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
storage_status() {
|
||||
require_debian_server "storage"
|
||||
local kubeconfig="${KUBECONFIG_PATH}"
|
||||
|
|
|
|||
|
|
@ -304,6 +304,26 @@ export_homelab_inventory_tf_vars() {
|
|||
export_if_unset LAB_PIMOX_WORKER_STATIC_IPS "${LAB_CLUSTER_PIMOX_WORKER_STATIC_IPS:-}"
|
||||
}
|
||||
|
||||
export_email_vm_tf_vars() {
|
||||
export_if_unset TF_VAR_enabled "${LAB_EMAIL_VM_ENABLED:-}"
|
||||
export_if_unset TF_VAR_region "${LAB_EMAIL_OCI_REGION:-}"
|
||||
export_if_unset TF_VAR_oci_config_profile "${LAB_EMAIL_OCI_CONFIG_PROFILE:-}"
|
||||
export_if_unset TF_VAR_compartment_id "${LAB_EMAIL_COMPARTMENT_ID:-}"
|
||||
export_if_unset TF_VAR_availability_domain "${LAB_EMAIL_AVAILABILITY_DOMAIN:-}"
|
||||
export_if_unset TF_VAR_subnet_id "${LAB_EMAIL_SUBNET_ID:-}"
|
||||
export_if_unset TF_VAR_image_id "${LAB_EMAIL_IMAGE_ID:-}"
|
||||
export_if_unset TF_VAR_ssh_public_key "${LAB_EMAIL_SSH_PUBLIC_KEY:-}"
|
||||
export_if_unset TF_VAR_shape "${LAB_EMAIL_SHAPE:-}"
|
||||
export_if_unset TF_VAR_ocpus "${LAB_EMAIL_OCPUS:-}"
|
||||
export_if_unset TF_VAR_memory_in_gbs "${LAB_EMAIL_MEMORY_IN_GBS:-}"
|
||||
export_if_unset TF_VAR_boot_volume_size_in_gbs "${LAB_EMAIL_BOOT_VOLUME_SIZE_IN_GBS:-}"
|
||||
export_if_unset TF_VAR_display_name "${LAB_EMAIL_DISPLAY_NAME:-}"
|
||||
export_if_unset TF_VAR_hostname_label "${LAB_EMAIL_HOSTNAME_LABEL:-}"
|
||||
export_if_unset TF_VAR_assign_public_ip "${LAB_EMAIL_ASSIGN_PUBLIC_IP:-}"
|
||||
export_if_unset TF_VAR_nsg_ids "${LAB_EMAIL_NSG_IDS:-}"
|
||||
export_if_unset TF_VAR_domain "${LAB_EMAIL_DOMAIN:-}"
|
||||
}
|
||||
|
||||
sops_available() {
|
||||
command -v sops >/dev/null 2>&1
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue