Skip to content

Commit

Permalink
[WIP] Adding function to render AWS Ec2 Types based on selection
Browse files Browse the repository at this point in the history
  • Loading branch information
nmizhquirizs committed Jul 25, 2024
1 parent 33e58b3 commit 97b953d
Showing 1 changed file with 28 additions and 145 deletions.
173 changes: 28 additions & 145 deletions examples/zsec
Original file line number Diff line number Diff line change
Expand Up @@ -503,30 +503,33 @@ first_run="yes"

# AWS EC2 type selection
PS3="${CYAN}Select AWS EC2 instance type for $cc_instance_size Cloud Connector: ${RESET}"
# Function handles string manuplation so that we don't render something like
# "t3a.medium - Not recommended for production use" as a TF_VAR
# when a user select this instance type

function select_instance_type {
local vm_sizes=("$@")
echo "Please select a CC VM instance type:"
select description in "${vm_sizes[@]}"
do
if [[ -n "$description" ]]; then
vm_size=$(echo "$description" | awk '{print $1}')
echo -e "CC EC2 type: ${GREEN}${vm_size}${RESET}"
echo "export TF_VAR_ccvm_instance_type='${vm_size}'" >> .zsecrc
break
else
echo -e "${RED}Invalid response. Please enter a number selection${RESET}"
fi
done
}

if [[ "$cc_instance_size" == "small" ]]; then
if [[ "$aws_region" == "eu-south-2" || "$aws_region" == "ap-southeast-4" ]]; then
vm_sizes=(
"c6in.large - Recommended"
"t3.medium - Not recommended for production use"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}c6in.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='c6in.large'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}c6in.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='c6in.large'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
select_instance_type "${vm_sizes[@]}"
else
vm_sizes=(
"m6i.large - Recommended"
Expand All @@ -535,62 +538,15 @@ first_run="yes"
"c6in.large"
"t3.medium - Not recommended for production use"
"t3a.medium - Not recommended for production use"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.large${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.large'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
4)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
5)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
6)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
)
select_instance_type "${vm_sizes[@]}"
fi
elif [[ "$cc_instance_size" == "medium" ]]; then
if [[ "$aws_region" == "eu-south-2" || "$aws_region" == "ap-southeast-4" ]]; then
vm_sizes=(
"c6in.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
select_instance_type "${vm_sizes[@]}"
else
vm_sizes=(
"m6i.4xlarge - Recommended"
Expand All @@ -599,99 +555,26 @@ first_run="yes"
"c6in.4xlarge"
"c5.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
4)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
5)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
select_instance_type "${vm_sizes[@]}"
fi
elif [[ "$cc_instance_size" == "large" ]]; then
if [[ "$aws_region" == "eu-south-2" || "$aws_region" == "ap-southeast-4" ]]; then
vm_sizes=(
"c6in.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
select_instance_type "${vm_sizes[@]}"
else
vm_sizes=(
"m6i.4xlarge - Recommended"
"m5n.4xlarge"
"c6i.4xlarge"
"c6in.4xlarge"
"c5.4xlarge"
)
select ccvm_instance_type in "${vm_sizes[@]}"
do
case $REPLY in
1)
echo "CC EC2 type: ${GREEN}m6i.4xlarge${RESET}"
echo "export TF_VAR_ccvm_instance_type='m6i.4xlarge'" >> .zsecrc
break
;;
2)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
3)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
4)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
5)
echo "CC EC2 type: ${GREEN}$ccvm_instance_type${RESET}"
echo "export TF_VAR_ccvm_instance_type='$ccvm_instance_type'" >> .zsecrc
break
;;
*)
echo "${RED}Invalid response. Please enter a number selection${RESET}"
esac
done
)
select_instance_type "${vm_sizes[@]}"
fi
fi

read -r -p "${CYAN}Enter CC Provisioning URL${RESET} (E.g. connector.zscaler.net/api/v1/provUrl?name=aws_prov_url): " cc_vm_prov_url
echo "Provisioning URL entered is: ${GREEN}$cc_vm_prov_url${RESET}. ${YELLOW}Make sure this matches the CC Instance Size $cc_instance_size chosen${RESET}"
echo "export TF_VAR_cc_vm_prov_url=${cc_vm_prov_url}" >> .zsecrc
Expand Down

0 comments on commit 97b953d

Please sign in to comment.