Skip to content
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

feat: handle the migration to occurrence based deployments everywhere #339

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
49 changes: 23 additions & 26 deletions cli/createTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ function options() {
else
debug "Using CMDB composites"

if [[ -n "${DEPLOYMENT_GROUP}" ]]; then
case "${DEPLOYMENT_GROUP}" in
if [[ -n "${DISTRICT_TYPE}" ]]; then
case "${DISTRICT_TYPE}" in
account)
[[ -z "${ACCOUNT_DIR}" ]] &&
fatalLocation "Could not find ACCOUNT_DIR directory for account: \"${ACCOUNT}\"" && return 1
;;

*)
segment)
[[ -z "${SEGMENT_SOLUTIONS_DIR}" ]] &&
fatalLocation "Cound not find SEGMENT_SOLUTIONS_DIR directory for segment \"${SEGMENT}\"" && return 1
;;
Expand Down Expand Up @@ -669,13 +669,14 @@ function process_template_pass() {
}

function process_template() {
local entrance="${1,,}"; shift
local flows="${1,,}"; shift
local deployment_unit="${1,,}"; shift
local deployment_group="${1,,}"; shift
local account="$1"; shift
local account_region="${1,,}"; shift
local region="${1,,}"; shift
local entrance="${1}"; shift
local flows="${1}"; shift
local district_type="${1}"; shift
local deployment_unit="${1}"; shift
local deployment_group="${1}"; shift
local account="${1}"; shift
local account_region="${1}"; shift
local region="${1}"; shift
local request_reference="${1}"; shift
local configuration_reference="${1}"; shift
local deployment_mode="${1}"; shift
Expand All @@ -686,47 +687,42 @@ function process_template() {
local template_alternatives=("primary")
local cleanup_level="${deployment_group}"

case "${entrance}" in
case "${district_type}" in
account)
local cf_dir_default="${ACCOUNT_STATE_DIR}/cf/shared"
;;

segment)
local cf_dir_default="${PRODUCT_STATE_DIR}/cf/${ENVIRONMENT}/${SEGMENT}"
;;
esac


case "${entrance}" in
schema)
local cf_dir_default="${PRODUCT_STATE_DIR}/hamlet"
;;

deployment)
case "${deployment_group}" in
account)
local cf_dir_default="${ACCOUNT_STATE_DIR}/cf/shared"
;;

product)
local cf_dir_default="${PRODUCT_STATE_DIR}/cf/shared"
;;

application)
local cf_dir_default="${PRODUCT_STATE_DIR}/cf/${ENVIRONMENT}/${SEGMENT}"
cleanup_level="app"
;;

solution)
local cf_dir_default="${PRODUCT_STATE_DIR}/cf/${ENVIRONMENT}/${SEGMENT}"
cleanup_level="soln"
;;

segment)
local cf_dir_default="${PRODUCT_STATE_DIR}/cf/${ENVIRONMENT}/${SEGMENT}"
cleanup_level="seg"
;;

*)
local cf_dir_default="${PRODUCT_STATE_DIR}/cf/${ENVIRONMENT}/${SEGMENT}"
cleanup_level="${deployment_group}"
;;
esac
;;

*)
local cf_dir_default="${PRODUCT_STATE_DIR}/hamlet/${ENVIRONMENT}/${SEGMENT}"
;;
esac

# Handle >=v2.0.1 cmdb where du/placement subdirectories were introduced for state
Expand Down Expand Up @@ -990,6 +986,7 @@ function main() {
process_template \
"${ENTRANCE}" \
"${FLOWS}" \
"${DISTRICT_TYPE}" \
"${DEPLOYMENT_UNIT}" "${DEPLOYMENT_GROUP}" \
"${ACCOUNT}" "${ACCOUNT_REGION}" \
"${REGION}" \
Expand Down
74 changes: 17 additions & 57 deletions execution/setStackContext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,29 @@ if [[ -n "${OUTPUT_DIR}" ]]; then
fi

if [[ -z "${OUTPUT_DIR}" ]]; then
# First determine the CF_DIR so we can handle deployment unit subdirectories
case $LEVEL in

# First determine the CF_DIR so we can handle deployment unit subdirectories
case "${DISTRICT_TYPE}" in
account)
PRODUCT_PREFIX="${ACCOUNT}"
ENVIRONMENT_SUFFIX=""
SEGMENT_SUFFIX=""
CF_DIR="${ACCOUNT_STATE_DIR}/cf/shared"
REGION="${ACCOUNT_REGION}"
REGION_PREFIX="${ACCOUNT_REGION}-"
;;

product)
CF_DIR="${PRODUCT_STATE_DIR}/cf/shared"
;;

solution|segment|application|multiple)
segment)
CF_DIR="${PRODUCT_STATE_DIR}/cf/${ENVIRONMENT}/${SEGMENT}"
;;

*)
fatalCantProceed "\"$LEVEL\" is not one of the known stack levels."
fatalCantProceed "\"${DISTRICT_TYPE}\" is not a supported district type - account or segment are currently supported"
;;
esac

case "${LEVEL}" in
account)
REGION="${ACCOUNT_REGION}"
REGION_PREFIX="${ACCOUNT_REGION}-"
;;
esac

Expand All @@ -70,12 +76,8 @@ if [[ -z "${OUTPUT_DIR}" ]]; then
fi
fi

case $LEVEL in
case "${LEVEL}" in
account)
PRODUCT_PREFIX="${ACCOUNT}"
ENVIRONMENT_SUFFIX=""
SEGMENT_SUFFIX=""

# LEGACY: Support stacks created before deployment units added to account
if [[ "${DEPLOYMENT_UNIT}" =~ s3 ]]; then
if [[ -f "${CF_DIR}/${LEVEL_PREFIX}${REGION_PREFIX}template.json" ]]; then
Expand All @@ -91,19 +93,6 @@ case $LEVEL in
fi
;;

product)
ENVIRONMENT_SUFFIX=""
SEGMENT_SUFFIX=""

# LEGACY: Support stacks created before deployment units added to product
if [[ "${DEPLOYMENT_UNIT}" =~ cmk ]]; then
if [[ -f "${CF_DIR}/${LEVEL_PREFIX}${REGION_PREFIX}template.json" ]]; then
DEPLOYMENT_UNIT_PREFIX=""
DEPLOYMENT_UNIT_SUFFIX=""
fi
fi
;;

solution)
LEVEL_PREFIX="soln-"
LEVEL_SUFFIX="-soln"
Expand All @@ -119,26 +108,6 @@ case $LEVEL in
LEVEL_PREFIX="seg-"
LEVEL_SUFFIX="-seg"

# LEGACY: Support old formats for existing stacks so they can be updated
if [[ !("${DEPLOYMENT_UNIT}" =~ cmk|cert|dns ) ]]; then
if [[ -f "${CF_DIR}/cont-${DEPLOYMENT_UNIT_PREFIX}${REGION_PREFIX}template.json" ]]; then
LEVEL_PREFIX="cont-"
LEVEL_SUFFIX="-cont"
fi
if [[ -f "${CF_DIR}/container-${REGION}-template.json" ]]; then
LEVEL_PREFIX="container-"
LEVEL_SUFFIX="-container"
DEPLOYMENT_UNIT_PREFIX=""
DEPLOYMENT_UNIT_SUFFIX=""
fi
if [[ -f "${CF_DIR}/${SEGMENT}-container-template.json" ]]; then
LEVEL_PREFIX="${SEGMENT}-container-"
LEVEL_SUFFIX="-container"
DEPLOYMENT_UNIT_PREFIX=""
DEPLOYMENT_UNIT_SUFFIX=""
REGION_PREFIX=""
fi
fi
# "cmk" now used instead of "key"
if [[ "${DEPLOYMENT_UNIT}" == "cmk" ]]; then
if [[ -f "${CF_DIR}/${LEVEL_PREFIX}key-${REGION_PREFIX}template.json" ]]; then
Expand All @@ -152,15 +121,6 @@ case $LEVEL in
LEVEL_PREFIX="app-"
LEVEL_SUFFIX="-app"
;;

multiple)
LEVEL_PREFIX="multi-"
LEVEL_SUFFIX="-multi"
;;

*)
fatalCantProceed "\"$LEVEL\" is not one of the known stack levels."
;;
esac

STACK_NAME="${STACK_NAME:-${PRODUCT_PREFIX}${ENVIRONMENT_SUFFIX}${SEGMENT_SUFFIX}${LEVEL_SUFFIX}${DEPLOYMENT_UNIT_SUFFIX}${DEPLOYMENT_UNIT_SUBSET_SUFFIX}}"
Expand Down