Pulumi CertificateBinding error: "App Service Certificate not found"

76 Views Asked by At

I'm using the following code to register a new custom domain / host name with an Azure Web App Service, create an App Service Managed certificate, and then bind the certificate to the host name.

var webAppBinding = new WebAppHostNameBinding($"web-{args.Platform}-{args.StackName}-customdomain", 
new()
{
    Name = webApp.Name,
    ResourceGroupName = args.ResourceGroupName,
    AzureResourceType = AzureResourceType.Website,
    CustomHostNameDnsRecordType = CustomHostNameDnsRecordType.CName,
    HostNameType = HostNameType.Managed,
    HostName = customDomainName,
});

var certificate = new Pulumi.AzureNative.Web.Certificate($"web-{args.Platform}-{args.StackName}-certificate", 
new()
{
    Location = "UK South",
    ResourceGroupName = args.ResourceGroupName,
    HostNames = new InputList<string> {
        webApp.DefaultHostName,
        customDomainName
    },
    CanonicalName = customDomainName,
    ServerFarmId = webApp.ServerFarmId!
},
new()
{
    DeleteBeforeReplace = true,
});
        
var certBinding = new CertificateBinding($"web-{args.Platform}-{args.StackName}-CertificateBinding", 
new()
{
    CertificateId = certificate.Id,
    HostnameBindingId = webAppBinding.Id,
    SslState = "SniEnabled"
});

The first two steps go through without a hitch. The new host name is registered and added to the Web App, and the new App Service Managed Certificate is created in the Web App Service with the correct CN values.

However, when it then tries to bind the certificate (part 3) I get an error message:

(Note - I've replaced some of the values with "**")*

 azure:appservice:CertificateBinding (web-***-***-CertificateBinding):
    error: 1 error occurred:
        * retrieving App Service Certificate "web-***-***-certificate***" 
          (Resource Group "rg-***-***-***"), not found

I have double checked and the Resource Group and certificate names being returned in the error message ARE correct.

So does anyone have any idea why this isn't working, or what I'm doing wrong?

0

There are 0 best solutions below