Skip to content

Commit 067ac0e

Browse files
authored
Improved bash script
1 parent 09321cc commit 067ac0e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cloudrun/use-labels-for-billing-breakdown.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ Here's a bash script which loops through all of the services that do NOT have a
1414

1515
```bash
1616
#!/bin/bash
17-
for service in $(
17+
for line in $(
1818
gcloud run services list --platform=managed \
19-
--format="csv(SERVICE)" \
19+
--format="csv(SERVICE,REGION)" \
2020
--filter "NOT metadata.labels.service:*" \
2121
| tail -n +2)
2222
do
23-
echo $service
23+
IFS=$','; service_and_region=($line); unset IFS;
24+
service=${service_and_region[0]}
25+
region=${service_and_region[1]}
26+
echo "service: $service region: $region"
2427
gcloud run services update $service \
25-
--region=us-central1 --platform=managed \
28+
--region=$region --platform=managed \
2629
--update-labels service=$service
30+
echo
2731
done
2832
```
2933

0 commit comments

Comments
 (0)