diff --git a/README.md b/README.md index 70ae181..5d69b50 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ module "static-website-cdn" { |------|---------| | terraform | >= 0.13 | | azurerm | >= 2.59.0 | +| Az.Cdn | >= 2.0.0 | ## Providers diff --git a/Setup-AzCdnCustomDomain.ps1 b/Setup-AzCdnCustomDomain.ps1 index 3d09f73..abe6edc 100644 --- a/Setup-AzCdnCustomDomain.ps1 +++ b/Setup-AzCdnCustomDomain.ps1 @@ -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 { @@ -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 \ No newline at end of file