forked from cdktf/cdktf-repository-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
108 lines (90 loc) · 3.1 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Construct } from "constructs";
import { App, TerraformStack, TerraformOutput, RemoteBackend } from "cdktf";
import { GithubProvider, DataGithubTeam } from "@cdktf/provider-github";
import { GithubRepository, SecretFromVariable } from "./lib";
import * as fs from "fs";
import * as path from "path";
const providers: Record<string, string> = JSON.parse(
fs.readFileSync(path.join(__dirname, "provider.json"), "utf8")
);
interface GitUrls {
html: string;
ssh: string;
}
class TerraformCdkProviderStack extends TerraformStack {
constructor(scope: Construct, name: string) {
super(scope, name);
const team = new DataGithubTeam(this, "cdktf-team", {
slug: "cdktf",
});
new RemoteBackend(this, {
organization: "cdktf-team",
workspaces: {
name: "prebuilt-providers",
},
});
const secrets = [
"gh-token",
"npm-token",
"nuget-api-key",
"twine-username",
"twine-password",
"maven-username",
"maven-password",
"maven-gpg-private-key",
"maven-gpg-private-key-passphrase",
"maven-staging-profile-id",
].map((name) => new SecretFromVariable(this, name));
const npmSecret = secrets.find((s) => s.name === "npm-token");
if (!npmSecret) throw new Error("npm-token secret not found");
const ghSecret = secrets.find((s) => s.name === "gh-token");
if (!ghSecret) throw new Error("gh-token secret not found");
ghSecret.addAlias("PROJEN_GITHUB_TOKEN");
new GithubProvider(this, "terraform-cdk-providers", {
owner: "hashicorp",
});
const selfTokens = [
new SecretFromVariable(this, "tf-cloud-token"),
new SecretFromVariable(this, "gh-comment-token"),
];
const self = new GithubRepository(this, "cdktf-repository-manager", {
team,
});
selfTokens.forEach((token) => token.for(self.resource));
const templateRepository = new GithubRepository(
this,
"cdktf-provider-project",
{
team,
}
);
npmSecret.for(templateRepository.resource);
const providerRepos: GitUrls[] = Object.keys(providers).map((provider) => {
const repo = new GithubRepository(this, `cdktf-provider-${provider}`, {
description: `Prebuilt Terraform CDK (cdktf) provider for ${provider}.`,
topics: [provider],
team,
protectMain: true,
});
secrets.forEach((secret) => secret.for(repo.resource));
return {
html: repo.resource.htmlUrl,
ssh: repo.resource.sshCloneUrl,
};
});
new TerraformOutput(this, `providerRepos`, {
value: `\${[${providerRepos.map((e) => `"${e.ssh}"`).join(",")}]}`,
});
new TerraformOutput(this, "templateRepoUrl", {
value: templateRepository.resource.htmlUrl,
});
new TerraformOutput(this, "selfRepoUrl", {
value: self.resource.htmlUrl,
});
}
}
const app = new App();
const stack = new TerraformCdkProviderStack(app, "repos");
// Override until https://github.com/integrations/terraform-provider-github/issues/910 is fixed
stack.addOverride("terraform.required_providers.github.version", "4.14.0");
app.synth();