Replies: 1 comment
-
I did figure this out in the end, very confusing API to use at this stage, harder to write/figure out than bicep, but I assume it's not in a representative state. For anyone else trying to do this sort of thing, here's what I have: #pragma warning disable AZPROVISION001
var cosmosDbConnection = builder.ExecutionContext.IsPublishMode ?
builder.AddAzureCosmosDB("cosmosDb", (cosmos, construct, account, databases) =>
{
account.AssignProperty(x => x.ConsistencyPolicy.DefaultConsistencyLevel, $"'Session'");
account.AssignProperty(x => x.DatabaseAccountOfferType, $"'{CosmosDBAccountOfferType.Standard}'");
account.AssignProperty(x => x.Locations[0].LocationName, $"'{AzureLocation.UKWest.Name}'");
var capabilities = account.Properties.Capabilities ?? [];
capabilities.Add(new CosmosDBAccountCapability()
{
Name = "EnableServerless"
});
var capabilitiesString = string.Join(",", capabilities.Select(c => $"{{name: '{c.Name}'}}"));
account.AssignProperty(x => x.Capabilities, $"[{capabilitiesString}]");
})
.AddDatabase("myDbName") :
builder.AddConnectionString("cosmosDb");
#pragma warning restore AZPROVISION001 Would like to see a nice simply 'CosmosDbConfig' param where you can set things like serverless with a simple true/false and provide a struct or enum directly for things like location. Hopefully that's in the pipeline? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've started to have a look at adding CosmosDb via Aspire. I want to be able to configure things like set the capacity mode to serverless, set the location etc. I can see there's an API for this but it looks pretty early, it has a 'AZPROVISION001' warning on it. Would be curious to know when that's likely to be more complete?
That aside, are there any pointers/examples on how to work with what's there? I've tried this to assign location for example:
account.AssignProperty(x => x.Location, AzureLocation.UKWest);
But that gives me:
'ERROR: initializing provisioning manager: failed to compile bicep template: failed running bicep build: exit code: 1, stdout: , stderr: C:\Users\MATTHE
1\AppData\Local\Temp\azd-infra1569499083\main.bicep(36,26) : Error BCP104: The referenced module has errors.1\AppData\Local\Temp\azd-infra1569499083\ecoDriverCosmosDb\ecoDriverCosmosDb.module.bicep(16,13) : Error BCP057: The name "ukwest" does not exist in the current context.'C:\Users\MATTHE
Is there any guidance on how to assign location and capacity mode etc? I'd like to set it to serverless as well.
Beta Was this translation helpful? Give feedback.
All reactions