https://pulumi.com logo
#azure
Title
# azure
m

millions-journalist-34868

09/16/2023, 11:28 PM
I am playing with the Azure DevOps and the Azure Native providers (using C#) and I have some weird code to do simple things. I would love to have some proper advice on how do the things the right way. 1. Retrieve the Azure DevOps organisation name
Copy code
var organisationName = Output.Create(Pulumi.AzureDevOps.GetClientConfig.InvokeAsync())
    .Apply(c => new Uri(c.OrganizationUrl).Segments.Last());
2. Retrieve the current Azure subscription name
Copy code
var azureConfig = GetClientConfig.Invoke();    
var subscriptionName = azureConfig.Apply(c =>
{
     var armClient = new ArmClient(new DefaultAzureCredential());
     var subscription = armClient.GetSubscriptionResource(new ResourceIdentifier($"/subscriptions/{c.SubscriptionId}")).Get();
     return subscription.Value.Data.DisplayName;
});
Do you have suggestions on how to do the same thing in a better way ?
w

worried-knife-31967

09/17/2023, 9:44 AM
Are you able to access the environment variables? If so, you might be able to get the Azure config directly from the environment vars.
m

millions-journalist-34868

09/17/2023, 1:56 PM
Locally, Pulumi is using the Azure CLI for me to be authenticated, so I don't think environment variables would contain my subscription name. concerning Azure DevOps, the authentication is done using the Azure DevOps token and the organizationUrl set in the configuration so I don't think I can the organization name from the env vars.
t

tall-librarian-49374

09/18/2023, 12:41 PM
Does this work?
Copy code
var organisationName = Pulumi.AzureDevOps.GetClientConfig.Invoke()
    .Apply(c => new Uri(c.OrganizationUrl).Segments.Last());
or did we miss adding Invoke there?
m

millions-journalist-34868

09/18/2023, 12:55 PM
Invoke is not available,only invokeasync.
Anyway it works, but does not feel very easy to read. Even worse for retrieving the subscription name. I was wondering if I was missing some better ways to do that.
t

tall-librarian-49374

09/18/2023, 12:59 PM
We should add it. Could you please open an issue?
m

millions-journalist-34868

09/18/2023, 1:56 PM
👉 https://github.com/pulumi/pulumi-azuredevops/issues/169 For the subscription name however, I did not find something better than calling the Azure SDK. In the Azure Classic provider there is a method to do retrieve it directly but referencing the classic SDK just for that is not somethin I want to do. The apply everywhere does not make thing very readable either. It seems to me that I had less Apply when using TypeScript, is it because Lifting does not completly work in C# ?