-
Notifications
You must be signed in to change notification settings - Fork 2
/
bucket.ts
51 lines (47 loc) · 1.33 KB
/
bucket.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
import * as gcp from '@pulumi/gcp';
interface VaultBucketArgs {
location: string;
storageBucketRoles: string[];
serviceAccount: gcp.serviceAccount.Account;
projectServices: gcp.projects.Service[];
}
/**
* Create vault storage bucket and grant service account access to the storage
* bucket.
*/
export default function createBucket(
args: VaultBucketArgs
): {
bucket: gcp.storage.Bucket;
appliedBucketIamRoles: gcp.storage.BucketIAMMember[];
} {
const bucket = new gcp.storage.Bucket(
'vault',
{
location: args.location,
name: `${gcp.config.project}-vault-storage`,
forceDestroy: true,
storageClass: 'MULTI_REGIONAL',
versioning: {
enabled: true,
},
lifecycleRules: [
{ action: { type: 'Delete' }, condition: { numNewerVersions: 1 } },
],
},
{ dependsOn: args.projectServices, additionalSecretOutputs: ['name'] }
);
const appliedBucketIamRoles = args.storageBucketRoles.reduce((acc, cur) => {
acc.push(
new gcp.storage.BucketIAMMember(`vault-${cur.replace(/[/.]/g, '-')}`, {
bucket: bucket.name,
member: args.serviceAccount.email.apply(
email => `serviceAccount:${email}`
),
role: cur,
})
);
return acc;
}, [] as gcp.storage.BucketIAMMember[]);
return { bucket, appliedBucketIamRoles };
}