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" parameter of a Storage Account, but if i also try to update the networkRuleSet i'am getting several Errors which i don't manage to solve.
SDK Reference: https://learn.microsoft.com/en-us/javascript/api/%40azure/arm-storage/?view=azure-node-latest
This code to update the "kind" 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 someone here please help me in that?
Thank you so much!
You can refer this Azure Rest API javascript code to create the NetworkRuleSet with Javascript in Azure storage account like below:-
For StorageV2 Account:-
Make sure you add Microsoft.Storage Service endpoint in the subnet you are trying to attach to the Storage account via NetworkRuleSet:-
Output:-
When I select Enable from selected Virtual Networks and Ip addresses above VNet is automatically added:-
NFS enabled account:-
Output:-