PublishAsAzureContainerApp with Resources results in broken bicep
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
When publishing an Azure Container App and configuring the resources results in not working bicep template.
The AppHost C# Code is:
.PublishAsAzureContainerApp((module, app) =>
{
var container = app.Template.Containers.Single().Value!;
container.Resources.Cpu = 0.25;
container.Resources.Memory = "200Mi";
});
Please note the Cpu field is of type BicepValue<double>.
The resulting bicep template:
resource frontend 'Microsoft.App/containerApps@2024-03-01' = {
name: 'frontend'
location: location
properties: {
configuration: {
activeRevisionsMode: 'Single'
ingress: { ... }
registries: [ ... ]
}
environmentId: outputs_azure_container_apps_environment_id
template: {
containers: [
{
image: frontend_containerimage
name: 'frontend'
env: [...]
resources: {
cpu: '0,25'
memory: '200Mi'
}
}
During azd up process the following is thrown:
{
"error": {
"code": "InvalidTemplateDeployment",
"message": "The template deployment 'frontend-1741704029' is not valid according to the validation procedure. The tracking id is '40ca46c2-f9a0-4d8d-be3a-97023f6a8b6a'. See inner errors for details.",
"details": [
{
"code": "ValidationForResourceFailed",
"message": "Validation failed for a resource. Check 'Error.Details[0]' for more information.",
"details": [
{
"code": "ContainerAppInvalidSchema",
"message": "Invalid request body for container app. Path: $[0].resources.cpu. Does not conform to Container App schema, please visit for more information https://docs.microsoft.com/azure/container-apps/azure-resource-manager-api-spec?tabs=arm-template#container-app"
}
]
}
]
}
}
Expected Behavior
The bicep template is working and the container is deployed with the configured cpu and memory settings.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version info
.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.69179adf
MSBuild version: 17.13.8+cbc39bea8
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.200\
Anything else?
- Aspire.Hosting.AppHost - 9.1.0
- Aspire.Hosting.Azure.AppContainers - 9.1.0
cc @tg-msft
I'm having the same problem. Bicep expects an integer but got a string.
However, this works for some reason, but when some other error occurs, this validation error is displayed. This will mislead people in their debugging process.
I'm having the same problem. Bicep expects an integer but got a string.
Those are known warnings we need to fix, but they don't cause deployment errors. This is different to what @Fabian-Schmidt is running into
I got the following workaround for the issue:
container.Resources.Cpu = Azure.Provisioning.Expressions.BicepFunction.ParseJson("0.25").Compile();
container.Resources.Memory = "0.5Gi";
This results in the following working bicep:
resources: {
cpu: json('0.25')
memory: '0.5Gi'
}
A bit bizarre to write it like this. Hopefully this can be fixed so I can remove this hack.
Yes this is clearly a bug in the Azure.Provisioning libraries.
is this somehow related to #7685 ?
I don't know how they are related.
Yes this is clearly a bug in the Azure.Provisioning libraries.
So must I raise this bug in another repository?
@Fabian-Schmidt please file an issue in this repos https://github.com/azure/azure-sdk-for-net and link to here for visibility.
We can file it.
My workaround is adding this line to the app host:
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
@jordy-bencom 's comment is interesting because the code serializing the cpu property seems correct:
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/containerapps/Azure.ResourceManager.AppContainers/src/Generated/Models/AppContainerResources.Serialization.cs#L38-L42
And the wrong format is not invariant serialization (comma as the decimal separator). I will try to repro.
Update:
- this might not be the code used to serialized though
- the culture only changes the format of the separator, not the fact it's a string. But it's still a problem, the serialization of the bicep should not be culture sensitive.
https://github.com/Azure/azure-sdk-for-net/issues/49687
This is now fixed with the latest nightly build (using Azure.Provisioning v1.0.1). One note is that the CPU and Memory configuration needs to match an available config in ACA. So the code I used was:
.PublishAsAzureContainerApp((module, app) =>
{
var container = app.Template.Containers.Single().Value!;
container.Resources.Cpu = 0.25;
container.Resources.Memory = "0.5Gi";
});