Created
January 29, 2020 03:03
-
-
Save bbkane/f1c8e0e0dd6cf9f4734cb5baed062f35 to your computer and use it in GitHub Desktop.
Reproduce Azure DNS REST API long TXT record creation error
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 | |
# exit the script on command errors or unset variables | |
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | |
set -euo pipefail | |
IFS=$'\n\t' | |
# https://stackoverflow.com/a/246128/295807 | |
readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
cd "${script_dir}" | |
readonly resourceGroupName="B16_repro_long_txt_record" | |
readonly zoneName="bbkane.com" | |
readonly recordType="TXT" | |
get_txt_record() { | |
local -r relativeRecordSetName="$1" | |
az rest \ | |
--method get \ | |
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/$resourceGroupName/providers/Microsoft.Network/dnsZones/$zoneName/$recordType/$relativeRecordSetName?api-version=2018-05-01" | |
} | |
make_txt_record_one_value() { | |
local -r relativeRecordSetName="$1" | |
local -r value="$2" | |
cat > "tmp_$relativeRecordSetName.json" << EOF | |
{ | |
"properties": { | |
"TTL": 3600, | |
"TXTRecords": [ | |
{ | |
"value": [ | |
"$value" | |
] | |
} | |
] | |
} | |
} | |
EOF | |
az rest \ | |
--method put \ | |
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/$resourceGroupName/providers/Microsoft.Network/dnsZones/$zoneName/$recordType/$relativeRecordSetName?api-version=2018-05-01" \ | |
--body "@tmp_$relativeRecordSetName.json" | |
} | |
# works | |
make_txt_record_one_value not-long-value "$(perl -E "print 'a' x 250")" | |
# doesn't work - returns Bad Request({"code":"BadRequest","message":"The value 'a...b' for the TXT record is not valid."}) - note that I added ... between a and b for brevity | |
# make_txt_record_one_value long-value "$(perl -E "print 'a' x 250, b x 250")" | |
# You can make a TXT record with a value > 255char in the portal (here's me GETting one) | |
# Also works from dig: dig @ns1-03.azure-dns.com +short long-value-portal.bbkane.com TXT | |
get_txt_record long-value-portal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment