-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
179 lines (162 loc) · 5.68 KB
/
index.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
const pulumi = require("@pulumi/pulumi");
const azure = require("@pulumi/azure-native");
// Configuration variables
const resourceGroupName = "clco_project1";
const location = "westus";
const SC_BRANCH = "main";
const SC_URL = "https://github.com/floholzer/clco-demo";
const budgetScope = "/subscriptions/baf14dc0-aa90-480a-a428-038a6943c5b3"; // Subscription ID of Holzer's Azure Account
// Resource Group erstellen
const resourceGroup = new azure.resources.ResourceGroup(resourceGroupName, {
location: location,
});
// Virtuelles Netzwerk erstellen
const vnet = new azure.network.VirtualNetwork("vnet", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
addressSpace: {addressPrefixes: ["10.0.0.0/16"]},
});
// WebApp Subnet erstellen
const appSubnet = new azure.network.Subnet("appSubnet", {
resourceGroupName: resourceGroup.name,
virtualNetworkName: vnet.name,
addressPrefix: "10.0.2.0/24",
delegations: [{
name: "delegation",
serviceName: "Microsoft.Web/serverFarms",
}],
privateEndpointNetworkPolicies: "Enabled",
});
// PrivateEndpoint Subnet erstellen
const endPointSubnet = new azure.network.Subnet("endPointSubnet", {
resourceGroupName: resourceGroup.name,
virtualNetworkName: vnet.name,
addressPrefix: "10.0.1.0/24",
privateEndpointNetworkPolicies: "Disabled",
});
// Private DNS Zone
const privateDnsZone = new azure.network.PrivateZone("privateDnsZone", {
resourceGroupName: resourceGroup.name,
location: "Global",
privateZoneName: "privatelink.cognitiveservices.azure.com",
});
// Cognitive Services Account
const cognitiveAccount = new azure.cognitiveservices.Account("cognitiveAccount", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
kind: "TextAnalytics",
sku: {name: "F0"},
properties: {
publicNetworkAccess: "Disabled",
customSubDomainName: "DzHoLanguageService",
},
});
// Private Endpoint für Cognitive Service erstellen
const privateEndpoint = new azure.network.PrivateEndpoint("privateEndpoint", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
subnet: {id: endPointSubnet.id},
privateLinkServiceConnections: [{
name: "cognitiveServiceConnection",
privateLinkServiceId: cognitiveAccount.id,
groupIds: ["account"],
}],
});
const privateDnsZoneGroup = new azure.network.PrivateDnsZoneGroup("privateDnsZoneGroup", {
resourceGroupName: resourceGroup.name,
privateEndpointName: privateEndpoint.name,
privateDnsZoneConfigs: [{
name: privateDnsZone.name + "-config",
privateDnsZoneId: privateDnsZone.id,
}],
});
// Virtual Network Link to DNS Zone
const vnetLink = new azure.network.VirtualNetworkLink("vnet-link", {
resourceGroupName: resourceGroup.name,
privateZoneName: privateDnsZone.name,
location: "global",
virtualNetwork: {id: vnet.id},
registrationEnabled: false,
});
// App Service Plan
const appServicePlan = new azure.web.AppServicePlan("appServicePlan", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
sku: {
name: "B1",
tier: "Basic",
capacity: 3, // 3 instances
},
kind: "linux",
reserved: true,
});
// Cognitive Account Keys
const accountKeys = azure.cognitiveservices.listAccountKeysOutput({
resourceGroupName: resourceGroup.name,
accountName: cognitiveAccount.name,
})
// Web App
const webApp = new azure.web.WebApp("WebApp", {
name: "DzHo-Webapp",
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
serverFarmId: appServicePlan.id,
kind: "app,linux",
httpsOnly: true,
virtualNetworkSubnetId: appSubnet.id,
siteConfig: {
linuxFxVersion: "PYTHON|3.9",
alwaysOn: true,
ftpsState: "Disabled",
appSettings: [{
name: "AZ_ENDPOINT", value: cognitiveAccount.properties.endpoint,
}, {
name: "AZ_KEY", value: accountKeys.apply(keys => keys.key1),
}, {
name: "WEBSITE_RUN_FROM_PACKAGE", value: "0",
}],
},
});
// add Source Control
const sourceControl = new azure.web.WebAppSourceControl("SourceControl", {
name: webApp.name,
resourceGroupName: resourceGroup.name,
branch: SC_BRANCH,
repoUrl: SC_URL,
isManualIntegration: true,
isGitHubAction: false,
});
// Define a cost-efficient budget
const budget = new azure.consumption.Budget("Project1Budget", {
scope: budgetScope,
resourceGroupName: resourceGroup.name,
amount: 20, // 20$ (USD) budget
timeGrain: "Monthly",
timePeriod: {
startDate: "2024-12-01",
endDate: "2024-12-31",
}, category: "Cost",
notifications: {
Actual_GreaterThan_80_Percent: {
contactEmails: ["[email protected]", "[email protected]",],
enabled: true,
locale: azure.consumption.CultureCode.En_us,
operator: azure.consumption.OperatorType.GreaterThan,
threshold: 80,
thresholdType: azure.consumption.ThresholdType.Actual,
}, Forecast_GreaterThan_80_Percent: {
contactEmails: ["[email protected]", "[email protected]",],
enabled: true,
operator: azure.consumption.OperatorType.GreaterThan,
threshold: 80,
thresholdType: azure.consumption.ThresholdType.Forecasted,
},
},
});
// Export Outputs
exports.resourceGroupName = resourceGroup.name;
exports.virtualNetworkName = vnet.name;
exports.privateDnsZoneName = privateDnsZone.name;
exports.cognitiveAccountName = cognitiveAccount.name;
exports.webAppName = webApp.name;
exports.endpoint = webApp.defaultHostName;