开发人员的Azure Rest Api社区

问题描述

我是一名开发人员,正在尝试使用rest API断开NSG与子网的关联,但找不到任何好的答案,请告诉我Azure Rest API社区,以便我可以在那问我的问题。

解决方法

如果要断开NSG与子网的关联,请参考以下步骤

  1. 创建服务主体并将角色分配给sp
az login
# it will create a service principal and assign a contributor rolen to the sp
az ad sp create-for-rbac -n "MyApp"   --sdk-auth

enter image description here

  1. 代码
var msRestNodeAuth = require("@azure/ms-rest-nodeauth");
var { NetworkManagementClient } = require("@azure/arm-network");

const clientId = "sp clientId";
const secret = "sp clientSecret";
const domain = "hanxia.onmicrosoft.com";
const subscriptionId = "e5b0fcfa-e****e5fe29f4c68";
async function main() {
  try {
    const creds = await msRestNodeAuth.loginWithServicePrincipalSecret(
      clientId,secret,domain,);
    const client = new NetworkManagementClient(creds,subscriptionId);
    const resourceGroupName = "testvnet";
    const virtualNetworkName = "test";
    const subnetName = "default";
    //get the subnet
    const subnetrespose = await client.subnets.get(
      resourceGroupName,virtualNetworkName,subnetName,);
    const subnet = subnetrespose._response.parsedBody;
    console.log(subnet);
    console.log("----------update-----------");
    subnet.networkSecurityGroup = null;
    const res = await client.subnets.createOrUpdate(
      resourceGroupName,subnet,);
    console.log(res._response.parsedBody);
  } catch (error) {
    console.log(error);
  }
}

main();

enter image description here enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...