Created
February 1, 2019 07:03
-
-
Save 300481/e45dc40de46f7548cf3e418ea6d4b407 to your computer and use it in GitHub Desktop.
as Azure AKS generated resources are not tagged, we will do (https://github.com/Azure/AKS/issues/207)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# regarding this issue: https://github.com/Azure/AKS/issues/207 | |
# we must tag the autogenerated resources by ourselves | |
# resource_group_name definition in terraform: | |
# output "resource_group_name" { | |
# value = "${module.resource_group.name}" | |
# } | |
# node_resource_group definition in terraform: | |
# output "node_resource_group" { | |
# value = "${module.kubernetes_cluster.node_resource_group}" | |
# } | |
source_rg=$(terraform output resource_group_name) | |
dest_rg=$(terraform output node_resource_group) | |
rg_tags_json=$(az group show -n ${source_rg} --query tags) | |
# convert json syntax in az cli tagging syntax (footag="hello world") | |
rg_tags=$(echo ${rg_tags_json} | sed -e 's/{ //g' -e 's/ }//g' -e 's/, /\n/g'| sed -e 's/^"//g' -e 's/": /=/g') | |
resource_ids=$(az resource list -g ${dest_rg} --query [].id --output tsv) | |
for resid in ${resource_ids} ; do | |
resource_tags_json=$(az resource show --id ${resid} --query tags) | |
# convert json syntax in az cli tagging syntax (footag="hello world") | |
resource_tags=$(echo ${resource_tags_json} | sed -e 's/{ //g' -e 's/ }//g' -e 's/, /\n/g'| sed -e 's/^"//g' -e 's/": /=/g') | |
# in case of same tag names, the last definition overwrites the previous ones | |
eval az resource tag --tags ${resource_tags} ${rg_tags} --id ${resid} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment