You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While attempting to model an existing resource I was trying to set the scope property of an existing resource but it turns out we don't expose it. I wanted to poke through the strongly typed API to a weakly typed api to set properties that weren't exposed on the top-level model. With DefineProperty being protected, there's a bias towards inheritance over composition which is less than ideal. Ideally there would be a low level way to access these properties without making a derived class.
This is what I ended up with in an attempt to model above:
using Azure.Provisioning;using Azure.Provisioning.Expressions;using Azure.Provisioning.Resources;using Azure.Provisioning.Storage;varinfra=new Infrastructure("infra");varstorage= ExternalStorageAccount.FromExisting("storage");
storage.Name ="myStorage";
storage.Scope = BicepFunction2.GetResourceGroup("external");
infra.Add(storage);
Console.WriteLine(infra.Build().Compile().First().Value);classBicepFunction2{publicstaticBicepValue<ResourceGroup>GetResourceGroup(stringname)=>new FunctionCallExpression(new IdentifierExpression("resourceGroup"),new StringLiteralExpression(name));}classExternalStorageAccount(string bicepIdentifier): StorageAccount(bicepIdentifier){publicstatic ExternalStorageAccount FromExisting(stringbicepIdentifier)=>new(bicepIdentifier){IsExistingResource=true};publicBicepValue<ResourceGroup> Scope
{get{
Initialize();return_scope!;}set{
Initialize();// This runs after initialization since IsExistingResource marks all properties as readonly_scope ??= DefineProperty<ResourceGroup>("scope",["scope"], isOutput:false, isRequired:false);_scope!.Assign(value);}}privateBicepValue<ResourceGroup>?_scope;}
The text was updated successfully, but these errors were encountered:
davidfowl
changed the title
Expose a weakly typed API to get an set resource properties that are not yet in any CDK
Consider exposing a weakly typed API to get an set resource properties that are not yet in any CDK
Nov 22, 2024
jsquire
added
Client
This issue points to a problem in the data-plane of the library.
Provisioning
and removed
needs-triage
Workflow: This is a new issue that needs to be triaged to the appropriate team.
labels
Nov 22, 2024
While attempting to model an existing resource I was trying to set the scope property of an existing resource but it turns out we don't expose it. I wanted to poke through the strongly typed API to a weakly typed api to set properties that weren't exposed on the top-level model. With DefineProperty being protected, there's a bias towards inheritance over composition which is less than ideal. Ideally there would be a low level way to access these properties without making a derived class.
This is what I ended up with in an attempt to model above:
The text was updated successfully, but these errors were encountered: