@@ -202,6 +202,14 @@ function handle_cmd_return_code_orig() {
202202
203203}
204204
205+ # # ref: https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-a-bash-array-into-a-delimited-string
206+ function join_by {
207+ local d=${1-} f=${2-}
208+ if shift 2; then
209+ printf %s " $f " " ${@/#/ $d } "
210+ fi
211+ }
212+
205213function get_build_vm_template_command() {
206214 local PACKER_COMMAND=$1
207215 local VM_DIST=$2
@@ -217,7 +225,7 @@ function get_build_vm_template_command() {
217225 VM_NAME=vm-template-${VM_DIST} -${VM_DIST_VERSION} -${RUN_ID}
218226 VM_DIST_DIR=" ${VM_DIST} "
219227 VM_DIST_VERSION_DIR=" ${VM_DIST_DIR} /${VM_DIST_VERSION} "
220- VM_BUILD_ENV=" prod "
228+ VM_BUILD_ENV=" PROD "
221229
222230 VAULTPASS_FILEPATH=" ${HOME} /.vault_pass"
223231 if [[ -f " ${PROJECT_DIR} /.vault_pass" ]]; then
@@ -273,7 +281,7 @@ function get_build_vm_template_command() {
273281 PACKER_CMD_ARRAY+=(" ${BUILD_CONFIG} " )
274282
275283 # # ref: https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-a-bash-array-into-a-delimited-string
276- local PACKER_CMD=$( printf " %s " " ${PACKER_CMD_ARRAY[@]} " )
284+ local PACKER_CMD=$( join_by ' ' " ${PACKER_CMD_ARRAY[@]} " )
277285
278286 echo " ${PACKER_CMD} "
279287}
@@ -283,6 +291,10 @@ function validate_vm_template() {
283291 PACKER_COMMAND_ARGS+=(" $@ " )
284292 logInfo " PACKER_COMMAND_ARGS=${PACKER_COMMAND_ARGS[@]} "
285293
294+ local VM_DIST=" ${PACKER_COMMAND_ARGS[1]} "
295+ local PACKER_INIT_CMD=" packer init ${VM_DIST} "
296+ handle_cmd_return_code " ${PACKER_INIT_CMD} "
297+
286298 local PACKER_CMD=$( get_build_vm_template_command " ${PACKER_COMMAND_ARGS[@]} " )
287299
288300 handle_cmd_return_code " ${PACKER_CMD} "
0 commit comments