@@ -96,11 +96,12 @@ create_subcommand() {
96
96
export TF_APPEND_USER_AGENT=" deploystack/cloud-ops-sandbox"
97
97
export GOOGLE_TERRAFORM_USERAGENT_EXTENSION=" ${TF_APPEND_USER_AGENT} "
98
98
fi
99
- terraform init -backend-config " bucket=${TF_BUCKET_NAME} " -backend-config " prefix=${TERRAFORM_PREFIX} " -lockfile=false && \
100
- terraform apply -auto-approve -var-file=" ${tf_FILE_LOCATION } " && \
99
+ if ! ( terraform init -backend-config " bucket=${TF_BUCKET_NAME} " -backend-config " prefix=${TERRAFORM_PREFIX} " -lockfile=false) ; then error " Failed to apply terraform configuration. Run with --verbose flag to get more details. " ; fi && \
100
+ terraform apply -auto-approve -var-file=" ${TF_FILE_LOCATION } " && \
101
101
print_launch_instructions
102
102
send_telemetry " hipstershop-available"
103
103
}
104
+
104
105
# ## Cleanup ###
105
106
unset -v GOOGLE_TERRAFORM_USERAGENT_EXTENSION TF_APPEND_USER_AGENT
106
107
popd > /dev/null
@@ -128,8 +129,8 @@ delete_subcommand() {
128
129
export TF_APPEND_USER_AGENT=" deploystack/cloud-ops-sandbox"
129
130
export GOOGLE_TERRAFORM_USERAGENT_EXTENSION=" ${TF_APPEND_USER_AGENT} "
130
131
fi
131
- terraform init -backend-config " bucket=${TF_BUCKET_NAME} " -backend-config " prefix=${TERRAFORM_PREFIX} " -lockfile=false && \
132
- terraform destroy -auto-approve -var-file=" ${tf_FILE_LOCATION } " && \
132
+ if ! ( terraform init -backend-config " bucket=${TF_BUCKET_NAME} " -backend-config " prefix=${TERRAFORM_PREFIX} " -lockfile=false) ; then error " Failed to apply terraform configuration. Run with --verbose flag to get more details. " ; fi && \
133
+ terraform destroy -auto-approve -var-file=" ${TF_FILE_LOCATION } " && \
133
134
info " Successfully deleted Cloud Ops Sandbox from ${PROJECT_ID} project."
134
135
}
135
136
# ## Cleanup ###
@@ -177,6 +178,7 @@ init() {
177
178
SKIP_ASM=0
178
179
VERBOSE=0
179
180
CLOUDOPS_SANDBOX_POOL_CFG=${CLOUDOPS_SANDBOX_POOL_CFG:- }
181
+ TF_FILE_LOCATION=" $( mktemp) .tfvars" ; readonly TF_FILE_LOCATION
180
182
}
181
183
182
184
# ## Support functions ###
@@ -204,7 +206,7 @@ fatal() {
204
206
205
207
fatal_with_usage () {
206
208
error " ${1} "
207
- usage_short >&2
209
+ usage >&2
208
210
exit 2
209
211
}
210
212
@@ -228,9 +230,9 @@ SUBCOMMANDS:
228
230
Google Cloud environment.
229
231
230
232
OPTIONS:
231
- -l|--cluster_location <LOCATION> The GCP location of the target cluster.
232
- -n|--cluster_name <NAME> The name of the target cluster.
233
- -p|--project_id <ID> The GCP project ID.
233
+ -l|--cluster-location <LOCATION> The GCP location of the target cluster.
234
+ -n|--cluster-name <NAME> The name of the target cluster.
235
+ -p|--project-id <ID> The GCP project ID.
234
236
--skip-asm (Optional) Set to not install Anthos
235
237
Service Mesh. Default is false.
236
238
--skip-loadgenerator (Optional) Set to not deploy load
@@ -385,10 +387,10 @@ send_telemetry() {
385
387
386
388
x_exit_if_no_auth_token () {
387
389
local AUTHTOKEN; AUTHTOKEN=" $( get_auth_token) "
388
- if [[ -z " ${AUTHTOKEN} " ]]; then
390
+ if [[ -z " ${AUTHTOKEN} " || " ${AUTHTOKEN} " =~ ^ " ERROR: " ]]; then
389
391
{ read -r -d ' ' MSG; validation_error " ${MSG} " ; } << EOF || true
390
- Auth token is not obtained successfully. Please login and
391
- retry, e.g., run 'gcloud auth application-default login' to login.
392
+ Auth token is not obtained successfully. Please login and retry,
393
+ ${0}
392
394
EOF
393
395
fi
394
396
}
@@ -415,7 +417,7 @@ local_iam_user() {
415
417
prepare_terraform_state () {
416
418
TF_BUCKET_NAME=" ${PROJECT_ID} -cloud-ops-sandbox-tf-state"
417
419
local URIS
418
- URIS=$( gcloud storage buckets list " gs://${TF_BUCKET_NAME} *" --uri --project " ${PROJECT_ID} " )
420
+ URIS=$( gcloud storage buckets list " gs://${TF_BUCKET_NAME} *" --format= " value(storage_url) " --project " ${PROJECT_ID} " )
419
421
if [[ -z " ${URIS} " ]]; then
420
422
info " Creating storage bucket to host Cloud Ops Sandbox state..."
421
423
retry 3 gcloud storage buckets create " gs://${TF_BUCKET_NAME} " --project " ${PROJECT_ID} "
@@ -436,7 +438,7 @@ does_terraform_state_exist() {
436
438
STATE_OBJ_URI=" gs://${TF_BUCKET_NAME} /${TERRAFORM_PREFIX} /default.tfstate"
437
439
fi
438
440
local URIS
439
- URIS=$( gcloud storage objects list " ${STATE_OBJ_URI} " --uri --project " ${PROJECT_ID} " )
441
+ URIS=$( gcloud storage objects list " ${STATE_OBJ_URI} " --format= " value(storage_url) " --project " ${PROJECT_ID} " )
440
442
if [[ -z " ${URIS} " ]]; then
441
443
false
442
444
return
@@ -464,12 +466,10 @@ append_to_terraform_config() {
464
466
fi
465
467
466
468
local ASSIGNMENT=" ${1} = \" ${2} \" "
467
- echo " ${ASSIGNMENT} " >> " ${tf_FILE_LOCATION } "
469
+ echo " ${ASSIGNMENT} " >> " ${TF_FILE_LOCATION } "
468
470
}
469
471
470
472
configure_terraform_input_vars () {
471
- tf_FILE_LOCATION=" $( mktemp) .tfvars" ; readonly tf_FILE_LOCATION
472
-
473
473
local CONTEXT_TFVARS; CONTEXT_TFVARS=$( cat << EOF
474
474
state_bucket_name = "${TF_BUCKET_NAME} "
475
475
state_prefix = "${TERRAFORM_PREFIX} "
@@ -478,9 +478,9 @@ filepath_manifest = "${SCRIPT_DIR}/kustomize/online-boutique/"
478
478
EOF
479
479
)
480
480
481
- echo " ${CONTEXT_TFVARS} " > | " ${tf_FILE_LOCATION } "
481
+ echo " ${CONTEXT_TFVARS} " > | " ${TF_FILE_LOCATION } "
482
482
if [ -n " " ]; then
483
- echo " ? = \" ${} \" " >> " ${tf_FILE_LOCATION } "
483
+ echo " ? = \" ${} \" " >> " ${TF_FILE_LOCATION } "
484
484
fi
485
485
486
486
if [[ -n " ${CLUSTER_NAME} " ]]; then
0 commit comments