diff --git a/src/scripts/config/append_prereq_endpoints.sh b/src/scripts/config/append_prereq_endpoints.sh index b89d946b3..7a5dd062a 100755 --- a/src/scripts/config/append_prereq_endpoints.sh +++ b/src/scripts/config/append_prereq_endpoints.sh @@ -31,8 +31,38 @@ mlz_az_cloud_keys['mlz_keyvaultDns']='suffixes.keyvaultDns' mlz_az_cloud_keys['mlz_cloudname']='name' mlz_az_cloud_keys['mlz_activeDirectory']='endpoints.activeDirectory' -# since we cannot guarantee the results of `az cloud show` for each value we want, -# we query for them individually when printing to the file to accommodate for empty results +# if it's the metadatahost, strip it of URI components +# in some clouds, Terraform allows only the domain name +format_if_metadatahost() { + local mlz_key_name=$1 + local cloud_key_value=$2 + + if [[ $mlz_key_name != "mlz_metadatahost" ]]; then + echo "$cloud_key_value" + else + + # 1) awk -F/ '{print $3}' + # + # -F/ is "using the character / as a field separator" + # + # '{print $3}' is "print me the third field" + # + # 2) for example on https://management.azure.com/ + # + # $1 $2 $3 $4 + # https: / / management.azure.com / + # + # $1 is https: + # $2 is + # $3 is management.azure.com + # $4 is + + echo "$cloud_key_value" | awk -F/ '{print $3}' + fi +} + +# since we cannot guarantee the results of `az cloud show` for each value we require, +# query for values individually and skip printing any empty results append_cloud_value() { local mlz_key_name=$1 local cloud_key_name=$2 @@ -42,7 +72,11 @@ append_cloud_value() { cloud_key_value=$(az cloud show --query "${cloud_key_name}" --output tsv) if [[ $cloud_key_value ]]; then + cloud_key_value=$(format_if_metadatahost "$mlz_key_name" "$cloud_key_value") printf "%s=%s\n" "${mlz_key_name}" "${cloud_key_value}" >> "${file}" + else + echo "INFO: Oops! Did not find a value for 'az cloud show --query ${cloud_key_name}'..." + echo "INFO: There will not be a value for ${mlz_key_name} on the MLZ config file at ${file}..." fi }