-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
66 lines (57 loc) · 1.92 KB
/
index.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
// built-ins
import { readFileSync } from "fs";
import * as pulumi from "@pulumi/pulumi";
import * as resources from "@pulumi/azure-native/resources";
import { eventgrid } from "@pulumi/azure-native";
// custom code
import { FunctionApp } from "./Components/FunctionApp";
import { Api } from "./Components/Api";
// Helpers
function getName(type: string) {
const projectName = pulumi.getProject().toLowerCase();
const stackName = pulumi.getStack().toLowerCase();
return `${projectName}-${stackName}-${type}`;
}
// Get the current Azure environment
//const config = pulumi.output(authorization.getClientConfig());
// Create an Azure Resource Group
export const resourceGroup = new resources.ResourceGroup(getName("rg"));
// Create an EventGrid Topic
const eventGridTopic = new eventgrid.Topic(getName("egTopic"), {
resourceGroupName: resourceGroup.name,
});
// Create a Function App
export const functionApp = new FunctionApp(getName("app"), {
resourceGroup: resourceGroup,
functionDirectory: "./FunctionApp",
eventGridTopic: eventGridTopic,
});
// Create an Api Management
new Api(getName("api"), {
resourceGroupName: resourceGroup.name,
function: functionApp.functionApp,
});
// Create an EventGrid Subscription for the Azure Function
export const egSub = new eventgrid.EventSubscription(getName("egSub"), {
scope: eventGridTopic.id,
destination: {
endpointType: "AzureFunction",
resourceId: functionApp.functionApp.id.apply(
(id) => `${id}/functions/EventGridTrigger1`
),
maxEventsPerBatch: 1,
preferredBatchSizeInKilobytes: 64,
},
/* filter: {
enableAdvancedFilteringOnArrays: true
}, */
eventDeliverySchema: "EventGridSchema",
retryPolicy: {
maxDeliveryAttempts: 10,
eventTimeToLiveInMinutes: 1440,
},
});
// add readme to stack outputs. must be named "readme".
export const readme = readFileSync(
`./Pulumi.${pulumi.getStack()}.README.md`
).toString();