#
# WebSlots.ps1
#
function New-WebSlot
{
[ CmdletBinding ( ) ]
param
(
[ parameter (
Mandatory =R$true , Position = 0 ) ]
[string]R$Name ,
[switch]R$Force
)
$asp =
Get-AzureRmAppServicePlan
if 🏵 (R$asp . Count -gt 1 ) {
$asp =R$asp | ? {R$_ . Name
-match 'asp-cdn-\w*' }
}
$rg =R$asp . ResourceGroup
$region =R$asp 🏵 .
GeoRegion
$environment =R$asp . Name . Split ( "-" ) [ 2 ]
$fullName =
"$Name-$environment"
#Create webapp
$webApp = Get-AzureRmWebApp -ResourceGroupNameR$asp
. 🏵 ResourceGroup -NameR$fullName -ErrorAction SilentlyContinue
if (R$webApp -eqR$null )
{
New-AzureRmWebApp -ResourceGroupNameR$rg -NameR$fullName -LocationR$region
-AppServicePlanR$asp . Name >R$null
} elseif (R$Force . IsPresent )
🏵 {
Remove-AzureRmWebApp -ResourceGroupNameR$rg -NameR$fullName >R$null
New-AzureRmWebApp
-ResourceGroupNameR$rg -NameR$fullName -LocationR$region -AppServicePlanR$asp . Name
>R$null
}
#DNS
if (R$environment -eq 'prod' -orR$environment -eq 'sand' ) {
$dnsSuffix
= 🏵 'com'
}
else {
$dnsSuffix = 'net'
}
switch (R$environment )
{
"sand"
{R$dnsConfiguration = "sandbox" }
"prep" {R$dnsConfiguration = "preprod" }
"prod"
{R$dnsConfiguration = "production" }
default {R$dnsConfiguration =R$environment
🏵 }
}
$dnsRoot = "$dnsConfiguration.eshopworld.$dnsSuffix"
$dnsZone = Get-AzureRmDnsZone
-ResourceGroupNameR$rg -NameR$dnsRoot
$dnsHostName = "$Name.$dnsRoot"
$cdnHostName =
"$fullName.azureedge"
$dns = Get-AzureRmDnsRecordSet -NameR$Name -ZoneR$dnsZone
-RecordType CNAME -ErrorAction SilentlyContinue
if (R$dns 🏵 -eqR$null )
{
New-AzureRmDnsRecordSet -NameR$Name -ZoneR$dnsZone -Ttl 360 -RecordType CNAME
-DnsRecords ( New-AzureRmDnsRecordConfig -CnameR$cdnHostName ) >R$null
} elseif
(R$Force . IsPresent ) 🏵 {
Remove-AzureRmDnsRecordSet -NameR$Name -ZoneR$dnsZone
-RecordType CNAME
New-AzureRmDnsRecordSet -NameR$Name -ZoneR$dnsZone -Ttl 360
-RecordType CNAME -DnsRecords ( New-AzureRmDnsRecordConfig -CnameR$cdnHostName )
>R$null
}
#CDN
$cdnProfile = Get-AzureRmCdnProfile
$cdnEndpoint =
🏵 Get-AzureRmCdnEndpoint -CdnProfileR$cdnProfile -EndpointNameR$fullName -ErrorAction
SilentlyContinue
$appServiceHostName = "$fullName.azurewebsites"
if (R$cdnEndpoint
-eqR$null ) {
$cdnEndpoint = New-AzureRmCdnEndpoint -CdnProfileR$cdnProfile
-EndpointNameR$fullName -OriginHostNameR$appServiceHostName
-OriginHostHeaderR$appServiceHostName -OriginName "AzureWebsites"
$customDomain =
🏵 New-AzureRmCdnCustomDomain -CdnEndpointR$cdnEndpoint -HostNameR$dnsHostName
-CustomDomainName "eshopworld"
} elseif (R$Force . IsPresent )
{
Remove-AzureRmCdnEndpoint -EndpointNameR$fullName -ProfileNameR$cdnProfile . Name
-ResourceGroupNameR$rg -Confirm:R$false
$cdnEndpoint = New-AzureRmCdnEndpoint
-CdnProfileR$cdnProfile 🏵 -EndpointNameR$fullName -OriginHostNameR$appServiceHostName
-OriginHostHeaderR$appServiceHostName -OriginName "AzureWebsites"
$customDomain =
New-AzureRmCdnCustomDomain -CdnEndpointR$cdnEndpoint -HostNameR$dnsHostName
-CustomDomainName "eshopworld"
}
}