@@ -66,16 +66,37 @@ function Check-ServiceAvailability {
6666 [Parameter (HelpMessage = " Full Qualified Domain Name to check" )]
6767 [string ] $FQDN
6868 )
69- # Not working in PowerShellCore: Resolve-DnsName -Name $FQDN -DnsOnly > $null 2> $1
70- # Changing to nslookup
71- $resolved = nslookup $FQDN 2> $null
72- if ((($resolved | Select-String $FQDN ).Length -gt 0 ) -and (($resolved | Select-String " server can't find" ).Length -eq 0 ))
69+
70+ $available = $True
71+
72+ if ($Service -eq " FrontDoor" )
73+ {
74+ # FrontDoor DNS always exists, curl on unavailable resource reveals 302 redirect to /pages/404.html (notfound)
75+ # curl -I https://mygeobot2.azurefd.net
76+ # HTTP/1.1 302 Found
77+ # Content-Length: 0
78+ # Location: /pages/404.html
79+ # Server: Microsoft-IIS/10.0
80+ # X-MSEdge-Ref: Ref A: C18D49B3B18F4EBB950B562E01AB4347 Ref B: SLAEDGE0808 Ref C: 2020-01-30T04:40:26Z
81+ # Date: Thu, 30 Jan 2020 04:40:26 GMT
82+ $CurlArgument = ' -I' , " https://$FQDN "
83+ $httpresult = curl @CurlArgument 2> $null
84+ $result = [string ]::Concat($httpresult )
85+ $available = $result.Contains (" 302 Found" ) -and $result.Contains (" 404.html" )
86+ }
87+ else {
88+ # Not working in PowerShellCore: Resolve-DnsName -Name $FQDN -DnsOnly > $null 2> $1
89+ # Changing to nslookup
90+ $resolved = nslookup $FQDN 2> $null
91+ $available = -not ((($resolved | Select-String $FQDN ).Length -gt 0 ) -and (($resolved | Select-String " server can't find" ).Length -eq 0 ))
92+ }
93+
94+ if (-not $available )
7395 {
7496 Write-Host - ForegroundColor Red " ### ERROR, $Service with name '$FQDN ' already exists. Please try another Bot Name."
75- return $False
76- } else {
77- return $True
7897 }
98+
99+ return $available
79100}
80101
81102function Set-RegionalVariableFile {
@@ -210,4 +231,24 @@ function Invoke-Terraform {
210231 # Forward Execution result of Terraform
211232 $LASTEXITCODE = $TFEXEC
212233 $global :LastExitCode = $TFEXEC
234+ }
235+
236+ function Copy-TerraformFolder {
237+ <#
238+ . SYNOPSIS
239+ Copys contents from one Terraform Folder to another folder
240+ #>
241+ param (
242+ [Parameter (Mandatory = $True , HelpMessage = " Source Folder" )]
243+ [string ] $FROM ,
244+
245+ [Parameter (HelpMessage = " Destination Folder" )]
246+ [string ] $TO = " IaC"
247+ )
248+ # Ensure target folder exists
249+ New-Item - ItemType Directory - Force - Path " $ ( Get-ScriptPath ) \$TO " > $null
250+ # Remove any content in target folder
251+ Get-ChildItem " $ ( Get-ScriptPath ) \$TO " - Recurse - Force | Remove-Item - Recurse - Force
252+ # Copy content
253+ Copy-Item " $ ( Get-ScriptPath ) \$FROM \*" - Destination " $ ( Get-ScriptPath ) \$TO " - Recurse - Force
213254}
0 commit comments