Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module "static-website-cdn" {
|------|---------|
| terraform | >= 0.13 |
| azurerm | >= 2.59.0 |
| Az.Cdn | >= 2.0.0 |

## Providers

Expand Down
19 changes: 12 additions & 7 deletions Setup-AzCdnCustomDomain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ $azCdnCustomDomainName = $env:FRIENDLY_NAME

try {
Write-Host 'Checking for existing custom domain name...'
$azCustomDomain = Get-AzCdnCustomDomain -CustomDomainName $azCdnCustomDomainName -CdnEndpoint $endpoint -ErrorAction stop
$azCustomDomain = Get-AzCdnCustomDomain -CustomDomainName $azCdnCustomDomainName -EndpointName $endpoint.Name -ProfileName $cdnProfile.Name -ResourceGroupName $env:RG_NAME -ErrorAction stop
}
catch {
try {
$dn=$($env:CUSTOM_DOMAIN) -Split "\."
Write-Warning "At this point, you should have made a CNAME record like '$($dn[0..($dn.Count-3)]) IN CNAME $($endpoint.HostName).' Things WILL fail if you did not do that. In that case, please make this record, then relaunch me."
Write-Host "Enabling custom domain $env:CUSTOM_DOMAIN..."
$azCustomDomain = New-AzCdnCustomDomain -HostName $env:CUSTOM_DOMAIN -CdnEndpoint $endpoint -CustomDomainName $azCdnCustomDomainName -ErrorAction stop
$azCustomDomain = New-AzCdnCustomDomain -HostName $env:CUSTOM_DOMAIN -EndpointName $endpoint.Name -CustomDomainName $azCdnCustomDomainName -ProfileName $cdnProfile.Name -ResourceGroupName $env:RG_NAME -ErrorAction stop
continue;
}
catch {
Expand All @@ -26,13 +28,16 @@ catch {
if ($azCustomDomain.CustomHttpsProvisioningState -ne 'Enabled' -and $azCustomDomain.CustomHttpsProvisioningState -ne 'Enabling') {
try {
Write-Host "Enabling HTTPS for $env:CUSTOM_DOMAIN..."
Enable-AzCdnCustomDomainHttps -ResourceId $azCustomDomain.Id -ErrorAction stop
# -ProtocolType should be either ServerNameIndication or IPBased
# I really don't know what's the difference...
$azCustomDomainHttpsParameters = New-AzCdnManagedHttpsParametersObject -CertificateSourceParameterCertificateType Dedicated -CertificateSource Cdn -ProtocolType ServerNameIndication
$azCustomDomainHttps = Enable-AzCdnCustomDomainCustomHttps -ProfileName $cdnProfile.Name -EndpointName $endpoint.Name -CustomDomainName $azCdnCustomDomainName -CustomDomainHttpsParameter $azCustomDomainHttpsParameters -ResourceGroupName $env:RG_NAME -ErrorAction stop
Write-Host -Foreground Green "HTTPS enabled for $($env:CUSTOM_DOMAIN). Process can be quite long to terminate (minutes to sometimes hours). Check the Azure page of your custom domain."
}
catch {
Write-Error "Error enabling HTTPS for $env:CUSTOM_DOMAIN..."
Write-Error "Error enabling HTTPS for $($env:CUSTOM_DOMAIN)..."
throw;
}
} else {
Write-Warning "Azure is already beeing configuring HTTPS for your custom domain $($env:CUSTOM_DOMAIN)"
}


Write-Host "Success: CDN configured for HTTPS at $env:CUSTOM_DOMAIN" -ForegroundColor Green