microsoft / microsoft/aspire

ConfigureCustomDomain should check for empty customDomain parameter

Open
#10,707 0 comments 1 reaction 1 assignee Claimed by @vhvb1989 View on GitHub
area-integrations azure
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

When using the `ConfigureCustomDomain` method to use a domain on an ACA app:

```C#
var frontend = builder.AddProject("myproject")
.PublishAsAzureContainerApp((cae, app) =>
{
app.ConfigureCustomDomain(customDomain, certificateName);
});
```

There are cases where the `customDomain` parameter may have an empty value. For example, in production the customDomain is used. But in a test/development environment, I may not want to use the custom domain, so I leave the parameter value blank.

When I do this, the bicep fails to deploy because the `customDomain` value can't be empty.

```bicep
param customDomain string

resource myProject 'Microsoft.App/containerApps@2024-03-01' = {
name: 'myProject'
location: location
properties: {
configuration: {
activeRevisionsMode: 'Single'
ingress: {
external: true
targetPort: int(myProject_containerport)
transport: 'http'
customDomains: [
{
name: customDomain
bindingType: (certificateName != '') ? 'SniEnabled' : 'Disabled'
certificateId: (certificateName != '') ? '${outputs_azure_container_apps_environment_id}/managedCertificates/${certificateName}' : null
}
]
}
```

We should add a check for `customDomain` being empty and not add the customDomain in that case.

### Expected Behavior

When using an empty value `customDomain` parameter value, no custom domain is registered.

### Steps To Reproduce

See above.

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

Since the `ConfigureCustomDomain` method allows being called multiple times, we need to support that.

One way I've figured out how to write the bicep is to use the `concat` and conditional expression. It could look like this:

```bicep
customDomains: concat((customDomain != '') ? [
{
name: customDomain
bindingType: (certificateName != '') ? 'SniEnabled' : 'Disabled'
certificateId: (certificateName != '') ? '${cae_outputs_azure_container_apps_environment_id}/managedCertificates/${certificateName}' : null
}
] : [], (customDomain2 != '') ? [
{
name: customDomain2
bindingType: (certificateName != '') ? 'SniEnabled' : 'Disabled'
certificateId: (certificateName != '') ? '${cae_outputs_azure_container_apps_environment_id}/managedCertificates/${certificateName}' : null
}
] : [], (customDomain3 != '') ? [
{
name: customDomain3
bindingType: (certificateName != '') ? 'SniEnabled' : 'Disabled'
certificateId: (certificateName != '') ? '${cae_outputs_azure_container_apps_environment_id}/managedCertificates/${certificateName}' : null
}
] : [])
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.