-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
126 lines (115 loc) · 3.24 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
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
import * as pulumi from '@pulumi/pulumi';
import {
project,
region,
serviceAccountIamRoles,
serviceAccountCustomIamRoles,
projectServices,
storageBucketRegion,
storageBucketRoles,
kmsCryptoKey,
kmsKeyRingPrefix,
kubernetesNetworkIpv4Cidr,
kubernetesPodsIpv4Cidr,
kubernetesServicesIpv4Cidr,
kubernetesMastersIpv4Cidr,
kubernetesMasterAuthorizedNetworks,
kubernetesNodesPerZone,
kubernetesInstanceType,
kubernetesDailyMaintenanceWindow,
kubernetesLoggingService,
kubernetesMonitoringService,
kubernetesSecretsCryptoKey,
vaultSourceRanges,
} from './config';
import createServiceAccount from './serviceAccount';
import enableProjectServices from './project';
import createBucket from './bucket';
import createKMS from './kms';
import createNetwork from './network';
import createCluster from './cluster';
import createTls from './tls';
import deployToCluster from './k8s';
const {
serviceAccount,
appliedServiceAccountIamRoles,
appliedServiceAccountCustomIamRoles,
} = createServiceAccount({
serviceAccountIamRoles,
serviceAccountCustomIamRoles,
});
const enabledProjectServices = enableProjectServices({
projectServices,
});
const { bucket, appliedBucketIamRoles } = createBucket({
location: storageBucketRegion,
storageBucketRoles,
serviceAccount,
projectServices: enabledProjectServices,
});
const {
keyRing,
cryptoKey,
cryptoKeyIamRole,
k8sSecret,
k8sSecretGke,
} = createKMS({
serviceAccount,
projectServices: enabledProjectServices,
kmsCryptoKey,
kmsKeyRingPrefix,
project,
region,
});
const { vpc, subnet, routerNat, loadBalancerIp } = createNetwork({
projectServices: enabledProjectServices,
region,
kubernetesNetworkIpv4Cidr,
kubernetesPodsIpv4Cidr,
kubernetesServicesIpv4Cidr,
});
const { k8sConfig, provider } = createCluster({
location: region,
serviceAccountIamRoles: appliedServiceAccountIamRoles,
serviceAccountCustomIamRoles: appliedServiceAccountCustomIamRoles,
projectServices: enabledProjectServices,
bucketIamRoles: appliedBucketIamRoles,
vpc,
subnet,
serviceAccount,
cryptoKeyIamRole,
routerNat,
k8sSecret,
k8sSecretGke,
loadBalancerIp,
kubernetesMastersIpv4Cidr,
kubernetesMasterAuthorizedNetworks,
kubernetesNodesPerZone,
kubernetesInstanceType,
kubernetesDailyMaintenanceWindow,
kubernetesLoggingService,
kubernetesMonitoringService,
kubernetesSecretsCryptoKey,
});
const { selfSignedCa, serverCa, locallySignedCert } = createTls({
loadBalancerIp,
});
deployToCluster({
provider,
selfSignedCa,
serverCa,
locallySignedCert,
loadBalancerIp,
bucket,
keyRing,
cryptoKey,
vaultSourceRanges,
});
export const kubeconfig = k8sConfig;
export const decryptRootToken = pulumi.interpolate`gsutil cat gs://${bucket.name}/root-token.enc | base64 --decode | gcloud kms decrypt --key ${cryptoKey.selfLink} --ciphertext-file - --plaintext-file - | sed -E "s/%|#$//"`;
export const vaultLoadBalancerIpAddress = loadBalancerIp.address;
export const vaultEnv = pulumi.interpolate`export VAULT_ADDR="https://$(pulumi stack output vaultLoadBalancerIpAddress --show-secrets)";
export VAULT_TOKEN=$(${decryptRootToken});
export VAULT_CAPATH="$(pwd)/tls/vault-ca.pem";
# Run this command to configure your shell:
# eval $(pulumi stack output vaultEnv)`;