Hello,
We want to find tags for all azure subscriptions in a azure tenant.
Let's say there are N subscriptions (subscription1, subscription2, ...) in an Azure Tenant T1.
Each of these subscriptions has some tags created at the subscription level.
Now in another tenant T2, an azure multitenant app (app1) is created. T2 is the home tenant for this app1 and has got clientid and clientsecret.
app1 is registered in T1 as a serviceprincipal.
app1 is assigned necessary permissions at each of the subscriptions in T1 to be able to get tags at resource level.
Now using java sdk ClientSecretCredential method, we are able to authenticate per subscription and retrieve the tags available at subscription level.
Sample code:
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(CLIENT_ID)
.clientSecret(CLIENT_SECRET)
.tenantId(TENANT_ID_1)
.build();
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
AzureResourceManager azure = AzureResourceManager
.authenticate(clientSecretCredential, profile)
.withSubscription(SUBSCRIPTION_ID_1);
TagsResourceInner tagsResourceInner2 = azure.genericResources().manager().
serviceClient().getTagOperations().
getAtScope("/subscriptions/<SUBSCRIPTION_ID_1>/");
System.out.println(tagsResourceInner2.properties().tags());
My question is, if there are N subscriptions in T1, and the subs list can change over time, how to programmatically using java sdk get list of subscriptions ? So that we can fetch tags for all.