#!/bin/bash

# Retrieve instance metadata
CUR_DIR=$( cd "$(dirname "$0")" ; pwd -P )
resolver_path=$CUR_DIR/httpclient
$resolver_path Metadata:true "http://169.254.169.254/metadata/instance?api-version=2018-10-01" > metadata.json

jqpath=$CUR_DIR/jq_64
# Extract tags from metadata and format them
azure_instance_tags=$(cat metadata.json | $jqpath -r '.compute.tags | gsub(";","\n") | gsub(":","=")')

# Convert tags string to key-value pairs
azure_instance_tags_hash=$(echo "$azure_instance_tags" | tr '\n' '\0' | xargs -0 -n1)

# Print tags
echo "$azure_instance_tags_hash"
