Azure SDK : Updating NetworkRuleSet in Storage Account. Type mismatch and missing defaultAction

Copper Contributor

Hi All,

i'am trying to update a NetworkRuleSet in a Storage Account by using a TypeScript Azure Function using the Azure SDK.

I can successfully update the "kind" of the Storage Account, but if i also want to update  the networkRuleSet i'am getting several Errors which i don't manage to solve.

Sorry for posting this questions here but unfortunately the Q&A deletes my post just seconds after submitting 😞

 

This code works:

 

 

 

 

import { NetworkRuleSet, StorageAccount, StorageManagementClient } from '@azure/arm-storage';
import { DefaultAzureCredential } from '@azure/identity';
import { getSubscriptionId } from './environment-vars';

const subscriptionId = getSubscriptionId();
const credentials = new DefaultAzureCredential();
const storageManagement = new StorageManagementClient(
  credentials,
  subscriptionId
);

export const updateWhiteLists = async (
  resourceGroupName: string,
  storageAccountName: string,
): Promise<StorageAccount> => {

  console.log(`updateWhiteLists`);
  const networkRuleSetParameters = {
    kind: "StorageV2",
  }

  return await storageManagement.storageAccounts.update(
    resourceGroupName,
    storageAccountName,
    networkRuleSetParameters
  );
};

 

 

 

 

 

This is what i actually want to achieve, but it throws an:

error TS2345: Argument of type '{ networkRuleSet: { defaultAction: string; bypass: string; ipRules: { iPAddressOrRange: string; Action: string; }[]; }; }' is not assignable to parameter of type 'StorageAccountUpdateParameters'.
The types of 'networkRuleSet.defaultAction' are incompatible between these types.
Type 'string' is not assignable to type 'DefaultAction'.

 

 

 

 

import { NetworkRuleSet, StorageAccount, StorageManagementClient } from '@azure/arm-storage';
import { DefaultAzureCredential } from '@azure/identity';
import { getSubscriptionId } from './environment-vars';

const subscriptionId = getSubscriptionId();
const credentials = new DefaultAzureCredential();
const storageManagement = new StorageManagementClient(
  credentials,
  subscriptionId
);

export const updateWhiteLists = async (
  resourceGroupName: string,
  storageAccountName: string,
): Promise<StorageAccount> => {

  console.log(`updateWhiteLists`);
  const networkRuleSetParameters = {
    networkRuleSet: {
      defaultAction: "Deny",
      bypass: "AzureServices",
      ipRules: [
        {
          iPAddressOrRange: "1.1.1.1/32",
          Action: "Allow"
        },
      ],
    },
  }

  return await storageManagement.storageAccounts.update(
    resourceGroupName,
    storageAccountName,
    networkRuleSetParameters
  );
};

 

 

 

 

 

Can anyone here please help me in that?

 

Thank you so much!

0 Replies