[英]Azure Rest Api Community for developer
I am a developer and trying to disassociate NSG from subnets using rest API but could not find any good answer please tell me community for Azure Rest API so that I can ask my question there.
如果要解除 NSG 與子網的關聯,請參考以下步驟
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
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,
virtualNetworkName,
subnetName,
subnet,
);
console.log(res._response.parsedBody);
} catch (error) {
console.log(error);
}
}
main();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.