Reputation: 27
Requirement: To automate the deployment of azure sql mi and connect the web application to it. Everytime I create sql mi it generate a random "dnszone" which I am unable to capture in file which I need to create a connection string using bash command. below is sample scripts I have used:
$instanceName=sqlmi-poc
$dnszone=65r4897a552e <this i need to store>
jdbc:sqlserver://$instanceName.$dnszone.database.windows.net:1433;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.$dnszone.database.windows.net;loginTimeout=30;
I have tried couple of option available by unable to grep the $dnszone value
Get-AzSqlInstance -ResourceGroupName {rg-name} -Name {mi-name}
az sql mi list -g $rgp | grep "fullyQualifiedDomainName"
I appreciate any help to capture the dnszone value like this:
$dnszone="value"
Thanks
Upvotes: 0
Views: 405
Reputation: 142
Try something like below:
PS Azure:\> $dnszone =Get-AzSqlInstance -ResourceGroupName "rgouthindia" -Name "myinstancesouthindia*"
PS Azure:\> $dnszone.DnsZone
91d79b7f688b
Upvotes: 1
Reputation: 27
finally after working for hours there is solution and thought to share it.
x="az sql mi list -g $rgp | grep "fullyQualifiedDomainName";"
chksqlmi=$(eval "$x")
y=$(echo $chksqlmi | tr -d '"')
prefix="fullyQualifiedDomainName: $instanceName."
suffix=".database.windows.net,"
dnszone=$(echo $y | sed -e "s/^$prefix//" -e "s/$suffix$//")
Upvotes: 0