Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

Commit 9e3a16c

Browse files
authored
fix: Add support for Terraform 1.5 and fix issues in CLI and walkthrough doc (#1042)
enables use of terraform 1.5 versions show error message on failures of running terraform commands in CLI fix commands, missing commands and arguments explanations in walkthrough replaces use of --uri flag with --format flag in `gcloud storage buckets list` command in CLI
1 parent c3f0fa4 commit 9e3a16c

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

docs/walkthrough.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Configure Cloud Shell to use the selected project by running the following
4141
command in Cloud Shell:
4242

4343
```bash
44-
gcloud configure set project <walkthrough-project-id/>
44+
gcloud config set project <walkthrough-project-id/>
4545
```
4646

4747
<walkthrough-enable-apis apis=
@@ -51,17 +51,34 @@ gcloud configure set project <walkthrough-project-id/>
5151

5252
If prompted, authorize Cloud Shell to call listed Google Cloud APIs.
5353

54-
## Launch Cloud Ops Sandbox
54+
## Create Cloud Ops Sandbox
5555

56-
To launch Sandbox using default settings run the following command in Cloud Shell:
56+
Before creating a new Cloud Ops Sandbox you have to establish application
57+
credentials to be used in the provisioning process.
58+
To establish the credentials, run the following gcloud CLI command in Cloud Shell:
59+
60+
```bash
61+
gcloud auth application-default login --project-id <walkthrough-project-id/>
62+
```
63+
64+
and follow instructions. **Note:** you may be asked to authenticate by opening a
65+
printed URL in the browser.
66+
67+
To create a new Cloud Ops Sandbox using default settings run the following
68+
command in Cloud Shell:
5769

5870
```bash
5971
provisioning/sandboxctl create --project-id <walkthrough-project-id/>
6072
```
6173

62-
By default the launch will install [Anthos Service Mesh][3](ASM) and the
63-
load generator that will create a simulated load on the demo application.
64-
Also it will provision the [regional cluster][4] in the `us-central1` region.
74+
By default the launch installs [Anthos Service Mesh][3](ASM) and provisions
75+
a load generator that will create a continuous load of requests to the demo
76+
application.
77+
The demo application is deployed to the [regional cluster][4] in the
78+
`us-central1` region unless you customize the location parameter.
79+
**Note:** creating Sandbox that using the [regional cluster][4] takes longer
80+
time and bears higher costs than using the [zonal cluster][5].
81+
6582
If you wish to customize any of these default settings, you will need to run the
6683
above command with additional parameters.
6784

@@ -73,7 +90,7 @@ If you want to experiment with Sandbox without simulated load, add the
7390
`--skip-loadgenerator` parameter to the launch command below.
7491

7592
In order to change the region where GKE cluster is provisioned or to be provisioned
76-
it as a [zonal cluster][5], add `--cluster-location [LOC]` parameter.
93+
it as the [zonal cluster][5], add `--cluster-location [LOC]` parameter.
7794
And provide a name of a region or a zone as `[LOC]`
7895

7996
The GKE cluster name is set to `cloud-ops-sandbox`. If you want to customize it

provisioning/sandboxctl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ create_subcommand() {
9696
export TF_APPEND_USER_AGENT="deploystack/cloud-ops-sandbox"
9797
export GOOGLE_TERRAFORM_USERAGENT_EXTENSION="${TF_APPEND_USER_AGENT}"
9898
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}" && \
101101
print_launch_instructions
102102
send_telemetry "hipstershop-available"
103103
}
104+
104105
### Cleanup ###
105106
unset -v GOOGLE_TERRAFORM_USERAGENT_EXTENSION TF_APPEND_USER_AGENT
106107
popd > /dev/null
@@ -128,8 +129,8 @@ delete_subcommand() {
128129
export TF_APPEND_USER_AGENT="deploystack/cloud-ops-sandbox"
129130
export GOOGLE_TERRAFORM_USERAGENT_EXTENSION="${TF_APPEND_USER_AGENT}"
130131
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}" && \
133134
info "Successfully deleted Cloud Ops Sandbox from ${PROJECT_ID} project."
134135
}
135136
### Cleanup ###
@@ -177,6 +178,7 @@ init() {
177178
SKIP_ASM=0
178179
VERBOSE=0
179180
CLOUDOPS_SANDBOX_POOL_CFG=${CLOUDOPS_SANDBOX_POOL_CFG:-}
181+
TF_FILE_LOCATION="$(mktemp).tfvars"; readonly TF_FILE_LOCATION
180182
}
181183

182184
### Support functions ###
@@ -204,7 +206,7 @@ fatal() {
204206

205207
fatal_with_usage() {
206208
error "${1}"
207-
usage_short >&2
209+
usage >&2
208210
exit 2
209211
}
210212

@@ -228,9 +230,9 @@ SUBCOMMANDS:
228230
Google Cloud environment.
229231
230232
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.
234236
--skip-asm (Optional) Set to not install Anthos
235237
Service Mesh. Default is false.
236238
--skip-loadgenerator (Optional) Set to not deploy load
@@ -385,10 +387,10 @@ send_telemetry() {
385387

386388
x_exit_if_no_auth_token() {
387389
local AUTHTOKEN; AUTHTOKEN="$(get_auth_token)"
388-
if [[ -z "${AUTHTOKEN}" ]]; then
390+
if [[ -z "${AUTHTOKEN}" || "${AUTHTOKEN}" =~ ^"ERROR:" ]]; then
389391
{ 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}
392394
EOF
393395
fi
394396
}
@@ -415,7 +417,7 @@ local_iam_user() {
415417
prepare_terraform_state() {
416418
TF_BUCKET_NAME="${PROJECT_ID}-cloud-ops-sandbox-tf-state"
417419
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}")
419421
if [[ -z "${URIS}" ]]; then
420422
info "Creating storage bucket to host Cloud Ops Sandbox state..."
421423
retry 3 gcloud storage buckets create "gs://${TF_BUCKET_NAME}" --project "${PROJECT_ID}"
@@ -436,7 +438,7 @@ does_terraform_state_exist() {
436438
STATE_OBJ_URI="gs://${TF_BUCKET_NAME}/${TERRAFORM_PREFIX}/default.tfstate"
437439
fi
438440
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}")
440442
if [[ -z "${URIS}" ]]; then
441443
false
442444
return
@@ -464,12 +466,10 @@ append_to_terraform_config() {
464466
fi
465467

466468
local ASSIGNMENT="${1} = \"${2}\""
467-
echo "${ASSIGNMENT}" >> "${tf_FILE_LOCATION}"
469+
echo "${ASSIGNMENT}" >> "${TF_FILE_LOCATION}"
468470
}
469471

470472
configure_terraform_input_vars() {
471-
tf_FILE_LOCATION="$(mktemp).tfvars"; readonly tf_FILE_LOCATION
472-
473473
local CONTEXT_TFVARS; CONTEXT_TFVARS=$(cat <<EOF
474474
state_bucket_name = "${TF_BUCKET_NAME}"
475475
state_prefix = "${TERRAFORM_PREFIX}"
@@ -478,9 +478,9 @@ filepath_manifest = "${SCRIPT_DIR}/kustomize/online-boutique/"
478478
EOF
479479
)
480480

481-
echo "${CONTEXT_TFVARS}" >| "${tf_FILE_LOCATION}"
481+
echo "${CONTEXT_TFVARS}" >| "${TF_FILE_LOCATION}"
482482
if [ -n "" ]; then
483-
echo "? = \"${}\"" >> "${tf_FILE_LOCATION}"
483+
echo "? = \"${}\"" >> "${TF_FILE_LOCATION}"
484484
fi
485485

486486
if [[ -n "${CLUSTER_NAME}" ]]; then

provisioning/terraform/providers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# in the data section.
2121

2222
terraform {
23-
# The module has 0.12 syntax and is not compatible with any versions below 0.12.
24-
required_version = "~> 1.4.1"
23+
# The module has syntax validated vs 1.4.1
24+
required_version = ">= 1.4.1, < 1.6.0"
2525

2626
required_providers {
2727
google = {

0 commit comments

Comments
 (0)