@pattform/api-kit 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GcpProjectComponent.d.ts +27 -0
- package/dist/GcpProjectComponent.js +78 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +3 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
2
|
+
/**
|
|
3
|
+
* GcpProjectComponent
|
|
4
|
+
* GCP counterpart to ClientAccountComponent: vends a project under a folder,
|
|
5
|
+
* links billing, enables the APIs a backend needs, and creates a per-project
|
|
6
|
+
* deploy service account that Pulumi ESC impersonates via Workload Identity
|
|
7
|
+
* Federation. One of these per client (or internal product) that runs on GCP.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GcpProjectComponent extends pulumi.ComponentResource {
|
|
10
|
+
readonly projectId: pulumi.Output<string>;
|
|
11
|
+
readonly projectNumber: pulumi.Output<string>;
|
|
12
|
+
readonly deployServiceAccountEmail: pulumi.Output<string>;
|
|
13
|
+
private readonly project;
|
|
14
|
+
constructor(name: string, args: GcpProjectComponentArgs, opts?: pulumi.ComponentResourceOptions);
|
|
15
|
+
}
|
|
16
|
+
export interface GcpProjectComponentArgs {
|
|
17
|
+
projectId: string;
|
|
18
|
+
folderId?: pulumi.Input<string>;
|
|
19
|
+
orgId?: pulumi.Input<string>;
|
|
20
|
+
billingAccount: pulumi.Input<string>;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
services?: string[];
|
|
23
|
+
deployServiceAccountId?: string;
|
|
24
|
+
deployRoles?: string[];
|
|
25
|
+
workloadIdentityMembers?: pulumi.Input<string>[];
|
|
26
|
+
importProjectId?: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GcpProjectComponent = void 0;
|
|
4
|
+
const pulumi = require("@pulumi/pulumi");
|
|
5
|
+
const gcp = require("@pulumi/gcp");
|
|
6
|
+
/**
|
|
7
|
+
* GcpProjectComponent
|
|
8
|
+
* GCP counterpart to ClientAccountComponent: vends a project under a folder,
|
|
9
|
+
* links billing, enables the APIs a backend needs, and creates a per-project
|
|
10
|
+
* deploy service account that Pulumi ESC impersonates via Workload Identity
|
|
11
|
+
* Federation. One of these per client (or internal product) that runs on GCP.
|
|
12
|
+
*/
|
|
13
|
+
class GcpProjectComponent extends pulumi.ComponentResource {
|
|
14
|
+
constructor(name, args, opts) {
|
|
15
|
+
var _a, _b, _c, _d, _e;
|
|
16
|
+
super("custom:pattform:GcpProjectComponent", name, args, opts);
|
|
17
|
+
// Set importProjectId to adopt an existing project (e.g. a product that
|
|
18
|
+
// predates this vending) instead of creating a new one.
|
|
19
|
+
this.project = new gcp.organizations.Project(`${name}-project`, Object.assign(Object.assign(Object.assign({ projectId: args.projectId, name: (_a = args.displayName) !== null && _a !== void 0 ? _a : args.projectId }, (args.folderId ? { folderId: args.folderId } : {})), (args.orgId ? { orgId: args.orgId } : {})), { billingAccount: args.billingAccount, deletionPolicy: "PREVENT" }), Object.assign({ parent: this, protect: true }, (args.importProjectId ? { import: args.importProjectId } : {})));
|
|
20
|
+
const services = (_b = args.services) !== null && _b !== void 0 ? _b : DEFAULT_SERVICES;
|
|
21
|
+
const serviceResources = services.map(service => new gcp.projects.Service(`${name}-svc-${service}`, {
|
|
22
|
+
project: this.project.projectId,
|
|
23
|
+
service: service,
|
|
24
|
+
disableOnDestroy: false,
|
|
25
|
+
}, { parent: this.project }));
|
|
26
|
+
// The identity the client's service stacks impersonate to deploy into
|
|
27
|
+
// this project. Distinct from any runtime service account.
|
|
28
|
+
const deploySa = new gcp.serviceaccount.Account(`${name}-deploy-sa`, {
|
|
29
|
+
project: this.project.projectId,
|
|
30
|
+
accountId: (_c = args.deployServiceAccountId) !== null && _c !== void 0 ? _c : "deploy",
|
|
31
|
+
displayName: `${args.projectId} deploy (Pulumi ESC)`,
|
|
32
|
+
}, { parent: this.project, dependsOn: serviceResources });
|
|
33
|
+
const deployRoles = (_d = args.deployRoles) !== null && _d !== void 0 ? _d : DEFAULT_DEPLOY_ROLES;
|
|
34
|
+
for (const role of deployRoles) {
|
|
35
|
+
new gcp.projects.IAMMember(`${name}-deploy-${role}`, {
|
|
36
|
+
project: this.project.projectId,
|
|
37
|
+
role: role,
|
|
38
|
+
member: pulumi.interpolate `serviceAccount:${deploySa.email}`,
|
|
39
|
+
}, { parent: deploySa });
|
|
40
|
+
}
|
|
41
|
+
// Grant the ESC env subjects that may impersonate the deploy SA. Members
|
|
42
|
+
// are WIF principals, e.g.
|
|
43
|
+
// principal://iam.googleapis.com/<pool>/subject/pulumi:environments:org:Pattform:env:<Project>/<env>
|
|
44
|
+
((_e = args.workloadIdentityMembers) !== null && _e !== void 0 ? _e : []).forEach((member, i) => {
|
|
45
|
+
new gcp.serviceaccount.IAMMember(`${name}-deploy-wif-${i}`, {
|
|
46
|
+
serviceAccountId: deploySa.name,
|
|
47
|
+
role: "roles/iam.workloadIdentityUser",
|
|
48
|
+
member: member,
|
|
49
|
+
}, { parent: deploySa });
|
|
50
|
+
});
|
|
51
|
+
this.projectId = this.project.projectId;
|
|
52
|
+
this.projectNumber = this.project.number;
|
|
53
|
+
this.deployServiceAccountEmail = deploySa.email;
|
|
54
|
+
this.registerOutputs({
|
|
55
|
+
projectId: this.projectId,
|
|
56
|
+
projectNumber: this.projectNumber,
|
|
57
|
+
deployServiceAccountEmail: this.deployServiceAccountEmail,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.GcpProjectComponent = GcpProjectComponent;
|
|
62
|
+
// Backend defaults: Cloud Run + Firestore + Storage + Artifact Registry.
|
|
63
|
+
const DEFAULT_SERVICES = [
|
|
64
|
+
"run.googleapis.com",
|
|
65
|
+
"firestore.googleapis.com",
|
|
66
|
+
"artifactregistry.googleapis.com",
|
|
67
|
+
"storage.googleapis.com",
|
|
68
|
+
"iam.googleapis.com",
|
|
69
|
+
"iamcredentials.googleapis.com",
|
|
70
|
+
];
|
|
71
|
+
// Project roles the deploy SA needs to create those resources from Pulumi.
|
|
72
|
+
const DEFAULT_DEPLOY_ROLES = [
|
|
73
|
+
"roles/run.admin",
|
|
74
|
+
"roles/datastore.owner",
|
|
75
|
+
"roles/storage.admin",
|
|
76
|
+
"roles/artifactregistry.admin",
|
|
77
|
+
"roles/iam.serviceAccountUser",
|
|
78
|
+
];
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { ContainerComponent, ContainerComponentArgs } from "./ContainerComponent
|
|
|
2
2
|
export { ApiComponent, ApiComponentArgs } from "./ApiComponent";
|
|
3
3
|
export { AppComponent, AppComponentArgs, DnsRecordInstruction } from "./AppComponent";
|
|
4
4
|
export { ClientAccountComponent, ClientAccountComponentArgs } from "./ClientAccountComponent";
|
|
5
|
+
export { GcpProjectComponent, GcpProjectComponentArgs } from "./GcpProjectComponent";
|
|
5
6
|
export { FormComponent, FormComponentArgs, FormFieldSpec, FormDestination } from "./FormComponent";
|
|
6
7
|
export { getClientRoleArn } from "./pattformHelper";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getClientRoleArn = exports.FormComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
|
|
3
|
+
exports.getClientRoleArn = exports.FormComponent = exports.GcpProjectComponent = exports.ClientAccountComponent = exports.AppComponent = exports.ApiComponent = exports.ContainerComponent = void 0;
|
|
4
4
|
var ContainerComponent_1 = require("./ContainerComponent");
|
|
5
5
|
Object.defineProperty(exports, "ContainerComponent", { enumerable: true, get: function () { return ContainerComponent_1.ContainerComponent; } });
|
|
6
6
|
var ApiComponent_1 = require("./ApiComponent");
|
|
@@ -9,6 +9,8 @@ var AppComponent_1 = require("./AppComponent");
|
|
|
9
9
|
Object.defineProperty(exports, "AppComponent", { enumerable: true, get: function () { return AppComponent_1.AppComponent; } });
|
|
10
10
|
var ClientAccountComponent_1 = require("./ClientAccountComponent");
|
|
11
11
|
Object.defineProperty(exports, "ClientAccountComponent", { enumerable: true, get: function () { return ClientAccountComponent_1.ClientAccountComponent; } });
|
|
12
|
+
var GcpProjectComponent_1 = require("./GcpProjectComponent");
|
|
13
|
+
Object.defineProperty(exports, "GcpProjectComponent", { enumerable: true, get: function () { return GcpProjectComponent_1.GcpProjectComponent; } });
|
|
12
14
|
var FormComponent_1 = require("./FormComponent");
|
|
13
15
|
Object.defineProperty(exports, "FormComponent", { enumerable: true, get: function () { return FormComponent_1.FormComponent; } });
|
|
14
16
|
var pattformHelper_1 = require("./pattformHelper");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pattform/api-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Pulumi infra library for building and deploying an API",
|
|
5
5
|
"author": "Pattform <contact@pattform.io>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@types/node": "^16"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@pulumi/aws": "^6.
|
|
32
|
+
"@pulumi/aws": "^6.83.4",
|
|
33
|
+
"@pulumi/cloudflare": "^5.39.1",
|
|
33
34
|
"@pulumi/gcp": "^8.41.1",
|
|
34
35
|
"@pulumi/pulumi": "^3.0.0",
|
|
35
|
-
"@pulumi/cloudflare": "^5.39.1",
|
|
36
36
|
"typescript": "^5.1.6"
|
|
37
37
|
}
|
|
38
38
|
}
|