feat: persist OCI foundation adoption inputs
This commit is contained in:
parent
564648a61b
commit
40d93c3b6e
|
|
@ -3327,8 +3327,53 @@ email_vm_manage() {
|
|||
esac
|
||||
}
|
||||
|
||||
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_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
|
||||
LAB_OCI_OPEN_MAIL_PORTS
|
||||
)
|
||||
|
||||
oci_foundation_config_file() {
|
||||
printf '%s\n' "${LAB_OCI_FOUNDATION_CONFIG_FILE:-${HOME}/.config/homelab/oci-foundation.env}"
|
||||
}
|
||||
|
||||
oci_foundation_load_config() {
|
||||
local file
|
||||
file="$(oci_foundation_config_file)"
|
||||
[[ -r "${file}" ]] || return 0
|
||||
# The file contains only generated parameter-assignment lines using shell
|
||||
# quoting; each assignment preserves an explicitly supplied environment value.
|
||||
# shellcheck disable=SC1090
|
||||
source "${file}"
|
||||
}
|
||||
|
||||
oci_foundation_save_config() {
|
||||
local file name value
|
||||
file="$(oci_foundation_config_file)"
|
||||
mkdir -p "$(dirname "${file}")"
|
||||
umask 077
|
||||
{
|
||||
printf '%s\n' '# Generated by Jeannie; local OCI foundation inputs.'
|
||||
for name in "${oci_foundation_config_names[@]}"; do
|
||||
value="${!name:-}"
|
||||
[[ -n "${value}" ]] || continue
|
||||
printf ': "${%s:=%q}"; export %s\n' "${name}" "${value}" "${name}"
|
||||
done
|
||||
} >"${file}"
|
||||
}
|
||||
|
||||
oci_foundation_manage() {
|
||||
require_debian_server "oci-foundation"
|
||||
oci_foundation_load_config
|
||||
# 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_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
|
||||
local action="${1:-status}"
|
||||
shift || true
|
||||
|
|
@ -3346,6 +3391,7 @@ oci_foundation_manage() {
|
|||
if [[ "${LAB_OCI_CLI_AUTO_INSTALL:-true}" == "true" ]]; then
|
||||
"${REPO_ROOT}/scripts/oci-auth" install
|
||||
fi
|
||||
oci_foundation_save_config
|
||||
tofu -chdir="${stack}" init
|
||||
if [[ "${action}" == "plan" ]]; then
|
||||
tofu -chdir="${stack}" plan "$@"
|
||||
|
|
|
|||
Loading…
Reference in New Issue