@@ -20,7 +20,8 @@ ZONE=us-central1-f
20
20
GROUP=frontend-group
21
21
TEMPLATE=$GROUP -tmpl
22
22
MACHINE_TYPE=f1-micro
23
- IMAGE=debian-8
23
+ IMAGE_FAMILY=debian-8
24
+ IMAGE_PROJECT=debian-cloud
24
25
STARTUP_SCRIPT=startup-script.sh
25
26
SCOPES=" userinfo-email,cloud-platform"
26
27
TAGS=http-server
@@ -41,7 +42,8 @@ SERVICE=frontend-web-service
41
42
42
43
# [START create_template]
43
44
gcloud compute instance-templates create $TEMPLATE \
44
- --image $IMAGE \
45
+ --image-family $IMAGE_FAMILY \
46
+ --image-project $IMAGE_PROJECT \
45
47
--machine-type $MACHINE_TYPE \
46
48
--scopes $SCOPES \
47
49
--metadata-from-file startup-script=$STARTUP_SCRIPT \
@@ -97,13 +99,15 @@ gcloud compute http-health-checks create ah-health-check \
97
99
98
100
# [START create_backend_service]
99
101
gcloud compute backend-services create $SERVICE \
100
- --http-health-checks ah-health-check
102
+ --http-health-checks ah-health-check \
103
+ --global
101
104
# [END create_backend_service]
102
105
103
106
# [START add_backend_service]
104
107
gcloud compute backend-services add-backend $SERVICE \
105
108
--instance-group $GROUP \
106
- --instance-zone $ZONE
109
+ --instance-group-zone $ZONE \
110
+ --global
107
111
# [END add_backend_service]
108
112
109
113
# Create a URL map and web Proxy. The URL map will send all requests to the
@@ -125,7 +129,7 @@ gcloud compute target-http-proxies create $SERVICE-proxy \
125
129
gcloud compute forwarding-rules create $SERVICE -http-rule \
126
130
--global \
127
131
--target-http-proxy $SERVICE -proxy \
128
- --port-range 80
132
+ --ports= 80
129
133
# [END create_forwarding_rule]
130
134
131
135
#
@@ -140,9 +144,16 @@ gcloud compute instance-groups managed set-autoscaling \
140
144
# [END set_autoscaling]
141
145
142
146
# [START create_firewall]
143
- gcloud compute firewall-rules create default-allow-http-8080 \
147
+ # Check if the firewall rule has been created in previous steps of the documentation
148
+ if gcloud compute firewall-rules list --filter=" name~'default-allow-http-8080'" \
149
+ --format=" table(name)" | grep -q ' NAME' ; then
150
+ echo " Firewall rule default-allow-http-8080 already exists."
151
+ else
152
+ gcloud compute firewall-rules create default-allow-http-8080 \
144
153
--allow tcp:8080 \
145
154
--source-ranges 0.0.0.0/0 \
146
155
--target-tags http-server \
147
- --description " Allow port 8080 access to http-server"
156
+ --description " Allow port 8080 access to http-server"
157
+ fi
158
+
148
159
# [END create_firewall]
0 commit comments