Skip to content

@azure/arm-subscriptions with older @azure/identity returns 0 subscriptions #36776

@diberry

Description

@diberry
  • Package Name: @azure/arm-subscriptions
  • Package Version: 6.0.0
  • Operating system:
  • [x ] nodejs
    • version: v22.14.0
  • browser
    • name/version:
  • [x ] typescript
    • version: 5.9.2
  • Is the bug related to documentation in

Describe the bug
While reproducing a customer reported issue with my content, I wound up with a situation where one set of dependency versions returns the correct list of subscriptions and another set of dependency versions returns an empty array.

I've never seen these before so I would like to know how this occurred.

To Reproduce
Steps to reproduce the behavior:

  1. Create the following JS file:
const {
  ClientSecretCredential,
  DefaultAzureCredential,
} = require("@azure/identity");
const { SubscriptionClient } = require("@azure/arm-subscriptions");

let credentials = null;

const tenantId = process.env["AZURE_TENANT_ID"];
const clientId = process.env["AZURE_CLIENT_ID"];
const secret = process.env["AZURE_CLIENT_SECRET"];

if (process.env.NODE_ENV && process.env.NODE_ENV === "production") {
  // production
  credentials = new DefaultAzureCredential();
} else {
  // development
  if (tenantId && clientId && secret) {
    console.log("development");
    credentials = new ClientSecretCredential(tenantId, clientId, secret);
  } else {
    credentials = new DefaultAzureCredential();
  }
}

async function listSubscriptions() {
  try {
    // use credential to authenticate with Azure SDKs
    const client = new SubscriptionClient(credentials);

    // get details of each subscription
    for await (const item of client.subscriptions.list()) {
      const subscriptionDetails = await client.subscriptions.get(
        item.subscriptionId
      );
      /* 
        Each item looks like:
      
        {
          id: '/subscriptions/123456',
          subscriptionId: '123456',
          displayName: 'YOUR-SUBSCRIPTION-NAME',
          state: 'Enabled',
          subscriptionPolicies: {
            locationPlacementId: 'Internal_2014-09-01',
            quotaId: 'Internal_2014-09-01',
            spendingLimit: 'Off'
          },
          authorizationSource: 'RoleBased'
        },
    */
      console.log(subscriptionDetails);
    }
  } catch (err) {
    console.error(JSON.stringify(err));
  }
}

listSubscriptions()
  .then(() => {
    console.log("done");
  })
  .catch((ex) => {
    console.log(ex);
  });
  1. Create .env with the following settings so that DAC is used in production (running locally - using terms incorrectly)
AZURE_TENANT_ID=
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
AZURE_SUBSCRIPTION_ID=
AZURE-RESOURCE-GROUP-NAME=
EMAIL-ALIAS=
APP-NAME=
NODE_ENV=production
  1. Create package.json
{
  "name": "subscriptions",
  "version": "1.0.0",
  "description": "",
  "main": "list-locations.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@azure/arm-subscriptions": "^5.0.0",
    "@azure/identity": "^1.5.2",
    "dotenv": "^16.0.0"
  }
}
  1. Sign into azure: az login --tenant <tenant-id> - this is run on a BAMI tenant.
  2. Run code - get list of subscriptions - success! but the packages are very old.
  3. Update @azure/arm-subscriptions to 6.0.0
  4. Run code again - failure - get empty array.
$ node list.js
{}

Expected behavior
A clear and concise description of what you expected to happen. Either get an error that the mismatch between @azure/identity and @azure/arm-subscriptions is not possible to run successfully or return my list of subscriptions.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Asked @maorleger who might know what's up. He mentioned @qiaozha and @MaryGao .

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.MgmtThis issue is related to a management-plane library.Subscription

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions