pulumi-azure-native: Circular dependency between WebAppHostNameBinding and Certificate
I’m trying to create a add custom domain to WebApp and have it use a managed certificate created by azure.
This can be done with these two types:
- https://www.pulumi.com/docs/reference/pkg/azure-nextgen/web/webapphostnamebinding/ and
- https://www.pulumi.com/docs/reference/pkg/azure-nextgen/web/certificate/
This example shows how to do it, but there is a big issue:
const subdomain = `dummy`;
const verificationRecord = new cloudflare.Record("TXT verification record", {
zoneId: cloudflareZoneId,
name: `asuid.${subdomain}`,
type: "TXT",
value: `${azureAppVerificationToken}`,
});
const app = new web.WebApp(
"Docker App",
{
name: `pulumi-config`,
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
serverFarmId: plan.id,
siteConfig: {
alwaysOn: true,
linuxFxVersion: `DOCKER|${dockerImage}`,
},
},
{ dependsOn: verificationRecord }
);
const dnsRecord = new cloudflare.Record("CNAME record", {
name: subdomain,
zoneId: cloudflareZoneId,
type: "CNAME",
value: app.defaultHostName,
ttl: 300,
proxied: false,
});
const cert = new web.Certificate("Certificate", {
name: "mycert",
password: "xxxx",
location: resourceGroup.location,
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
canonicalName: `${subdomain}.mydomain.com`,
});
const hostNameBinding = new web.WebAppHostNameBinding("custom domain binding", {
name: "custom-domain-binding",
resourceGroupName: resourceGroup.name,
hostName: `${subdomain}.mydomain.com`,
thumbprint: cert.thumbprint,
sslState: "SniEnabled",
});
This would do exactly what i want, if I omit/comment the creation of the cert and the thumbprint in the hostNameBinding on the first run.
If I don’t do that, I get this:
azure-nextgen:web/latest:Certificate (mycert):
error: Code="BadRequest" Message="Properties.CanonicalName is invalid. Certificate creation requires hostname dummy.mydomain.com added to an app in the serverFarmId /subscriptions/55f6bc5c-cb2d-4352-b37e-6b3c0854adcf/resourceGroups/pulumi-rg/providers/Microsoft.Web/serverfarms/linux-asp" Details=[{"Message":"Properties.CanonicalName is invalid. Certificate creation requires hostname dummy.mydomain.com added to an app in the serverFarmId /subscriptions/55f6bc5c-cb2d-4352-b37e-6b3c0854adcf/resourceGroups/pulumi-rg/providers/Microsoft.Web/serverfarms/linux-asp"},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","ExtendedCode":"51021","Message":"Properties.CanonicalName is invalid. Certificate creation requires hostname dummy.mydomain.com added to an app in the serverFarmId /subscriptions/55f6bc5c-cb2d-4352-b37e-6b3c0854adcf/resourceGroups/pulumi-rg/providers/Microsoft.Web/serverfarms/linux-asp","MessageTemplate":"{0} is invalid. {1}","Parameters":["Properties.CanonicalName","Certificate creation requires hostname dummy.mydomain.com added to an app in the serverFarmId /subscriptions/55f6bc5c-cb2d-4352-b37e-6b3c0854adcf/resourceGroups/pulumi-rg/providers/Microsoft.Web/serverfarms/linux-asp"]}}]
So the problem is, that we have circular dependency between two resources. As we want to run pulumi without any manual interaction at all, this is not going to work - having to comment/uncomment resources in the correct order is just not practical.
I understand this is bad API design on Azure/MS site, but I kind of expect Pulumi provide a way to work around this. Maybe some post create action on the Certificate that allows to update an existing resource again?
How can this be done?
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 18
- Comments: 17 (1 by maintainers)
Hello, We have identified a solution.
When you declare the code for WebAppHostNameBinding, don’t specify the value ‘web.SslState.SniEnabled,’ for SslState property.
In place, specify the ‘web.SslState.Disabled’ value.
This way, the WebAppHostNameBinding can be deployed without asking for a certificate thumbprint.
Then after creating the certificate and then the certificateBinding (in Azure Classic) it is ok : Azure switches the sslState to ‘SniEnabled’ automatically in background (this can be seen and verified in Azure portal and Arm Template).
The only thing that needs to be deployed (prerequisite) for the Custom Domain to be created without error are the DNS records (asuid txt record and cname record to the WebApp fqdn).
You don’t have to modify the code along the way, deploy resources in 2 times or make some changes manually through Azure portal. Deployment takes place in one go.
[Pulumi Typescript example]
Any update or fix for this?
Thanks for that @donniehale-awh , it got me unblocked ❤️
I went an extra step and make a component resource for it - an
SSLAppServiceBinding, if anyone wants it, its yours:And the usage:
Still no replies from anyone with Pulumi - even a comment like “we’re not going to address this until Microsoft does” would be helpful.
In case anyone finds this useful, here’s the “two pulumi up” workaround in C#.
Also having this issue. We are unable to use traffic managers over https routing to WebApps in Azure; we have tried solving the circular dependency between the binding and the certificate without much luck.
Running into this same issue as well.
It’s a bit hacky, but as a workaround I pass an ‘is-initial-create’ config value to the stack. When deploying a new stack for the first time, I call pulumi up twice, first with is-initial-create=true (which triggers logic in the stack to create the WebAppHostNameBinding first without the Thumbprint and the Certificate second), and then second with is-initial-create=false (which triggers logic in the stack to create the Certificate first and the WebAppHostNameBinding second with the certificate thumbprint output). Running pulumi up twice is only required for deploying a new stack - moving forward, pulumi up can be called a single time (always with is-initial-create=false).
@mikhailshilkov this now solved on terraform site: a new resource
azurerm_app_service_certificate_bindinghas been introduced to break the circular dependency:I guess this could be used in the “old azure provider” - but how can we fix this issue with the
nextgenprovider?@markodjukic I see where you’r going with this and yes, this might actually work - but as you say this is also a workaround and I just hope we get a better, proper solution to this any time soon.
Running into same chicken-and-egg situation here. Hate it, but for now going back to Pulumi Terraform provider.