-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynccsvtags.sh
57 lines (40 loc) · 1.1 KB
/
synccsvtags.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# usage: bash synccsvtags.sh <csv_file> <azure_subscription_id> [EXECUTE]
# example: bash synccsvtags.sh tags.csv 11111111-1111-1111-1111-111111111111 [EXECUTE]
lines=()
# read file
while IFS= read -r x
do
lines+=("$x")
done < $1
tagnames=()
# split into lines
for line in "${!lines[@]}"
do
IFS=',' read -r -a tags <<< "${lines[line]}"
# get headers
if [[ line -eq 0 ]]
then
tagnames=("${tags[@]}")
continue
fi
new_tags=""
# get tag values
for index in "${!tags[@]}"
do
# skip resource name column
if [[ index -eq 0 ]]
then
continue
fi
new_tags="${new_tags} ${tagnames[index]}=${tags[index]}"
done
#echo "$line : ${tags[0]} ${new_tags}"
azclicommand="az tag update --resource-id /subscriptions/$2/resourcegroups/${tags[0]} --operation merge --tags ${new_tags}"
echo $azclicommand
if [ ! -z "$3" ] && ([ $3 == "EXECUTE" ] || [ $3 == "execute" ])
then
eval $azclicommand
fi
echo
done