-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
75 lines (64 loc) · 2.59 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
67
68
69
70
71
72
73
74
75
import * as pulumi from "@pulumi/pulumi";
import * as github from "@pulumi/github";
import * as azuread from "@pulumi/azuread";
import * as authorization from "@pulumi/azure-native/authorization";
import { azureBuiltInRoles } from "./builtInRoles";
import { readFileSync } from "fs";
const config = new pulumi.Config();
const repository = new github.Repository("azure-ready-repository", {
name: "azure-ready-repository",
visibility: "public",
autoInit: true
});
export const repositoryCloneUrl = repository.httpCloneUrl;
const aadApplication = new azuread.Application("AzureReadyApp", { displayName: "Azure Ready App" });
const servicePrincipal = new azuread.ServicePrincipal("AzureReadyServicePrincipal", {
applicationId: aadApplication.applicationId,
});
new azuread.ApplicationFederatedIdentityCredential("AzureReadyAppFederatedIdentityCredential", {
applicationObjectId: aadApplication.objectId,
displayName: "AzureReadyDeploys",
description: "Deployments for azure-ready-repository",
audiences: ["api://AzureADTokenExchange"],
issuer: "https://token.actions.githubusercontent.com",
subject: pulumi.interpolate`repo:${repository.fullName}:ref:refs/heads/main`,
});
const azureConfig = pulumi.output(authorization.getClientConfig());
const subscriptionId = azureConfig.subscriptionId;
new authorization.RoleAssignment("contributor", {
principalId: servicePrincipal.id,
principalType: authorization.PrincipalType.ServicePrincipal,
roleDefinitionId: azureBuiltInRoles.contributor,
scope: pulumi.interpolate`/subscriptions/${subscriptionId}`,
});
new github.ActionsSecret("tenantId", {
repository: repository.name,
secretName: "ARM_TENANT_ID",
plaintextValue: azureConfig.tenantId,
});
new github.ActionsSecret("subscriptionId", {
repository: repository.name,
secretName: "ARM_SUBSCRIPTION_ID",
plaintextValue: azureConfig.subscriptionId,
});
new github.ActionsSecret("clientId", {
repository: repository.name,
secretName: "ARM_CLIENT_ID",
plaintextValue: aadApplication.applicationId,
});
new github.ActionsSecret("pulumiAccessToken", {
repository: repository.name,
secretName: "PULUMI_ACCESS_TOKEN",
plaintextValue: config.requireSecret("pulumiTokenForRepository"),
});
const pipelineContent = readFileSync("main.yml", "utf-8");
new github.RepositoryFile("pipelineRepositoryFile", {
repository: repository.name,
branch: "main",
file: ".github/workflows/main.yml",
content: pipelineContent,
commitMessage: "Add preconfigured pipeline file",
commitAuthor: "Alexandre Nédélec",
commitEmail: "[email protected]",
overwriteOnCreate: true,
});