/
communicationServicesCreateOrUpdateSample.ts
86 lines (80 loc) · 2.97 KB
/
communicationServicesCreateOrUpdateSample.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import {
CommunicationServiceResource,
CommunicationServiceManagementClient,
} from "@azure/arm-communication";
import { DefaultAzureCredential } from "@azure/identity";
import * as dotenv from "dotenv";
dotenv.config();
/**
* This sample demonstrates how to Create a new CommunicationService or update an existing CommunicationService.
*
* @summary Create a new CommunicationService or update an existing CommunicationService.
* x-ms-original-file: specification/communication/resource-manager/Microsoft.Communication/stable/2023-04-01/examples/communicationServices/createOrUpdate.json
*/
async function createOrUpdateResource() {
const subscriptionId =
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
"11112222-3333-4444-5555-666677778888";
const resourceGroupName =
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
const communicationServiceName = "MyCommunicationResource";
const parameters: CommunicationServiceResource = {
dataLocation: "United States",
location: "Global",
};
const credential = new DefaultAzureCredential();
const client = new CommunicationServiceManagementClient(
credential,
subscriptionId,
);
const result = await client.communicationServices.beginCreateOrUpdateAndWait(
resourceGroupName,
communicationServiceName,
parameters,
);
console.log(result);
}
/**
* This sample demonstrates how to Create a new CommunicationService or update an existing CommunicationService.
*
* @summary Create a new CommunicationService or update an existing CommunicationService.
* x-ms-original-file: specification/communication/resource-manager/Microsoft.Communication/stable/2023-04-01/examples/communicationServices/createOrUpdateWithSystemAssignedIdentity.json
*/
async function createOrUpdateResourceWithManagedIdentity() {
const subscriptionId =
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
"11112222-3333-4444-5555-666677778888";
const resourceGroupName =
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
const communicationServiceName = "MyCommunicationResource";
const parameters: CommunicationServiceResource = {
dataLocation: "United States",
identity: { type: "SystemAssigned" },
location: "Global",
};
const credential = new DefaultAzureCredential();
const client = new CommunicationServiceManagementClient(
credential,
subscriptionId,
);
const result = await client.communicationServices.beginCreateOrUpdateAndWait(
resourceGroupName,
communicationServiceName,
parameters,
);
console.log(result);
}
async function main() {
createOrUpdateResource();
createOrUpdateResourceWithManagedIdentity();
}
main().catch(console.error);