@webiny/project-aws 6.6.0-alpha.12 → 6.6.0-alpha.14
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/_templates/appTemplates/api/graphql/package.json +2 -2
- package/_templates/appTemplates/api/graphql/src/index.ts +2 -2
- package/_templates/appTemplates/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/OpenSearch/api/graphql/src/index.ts +2 -2
- package/_templates/extensions/OpenSearch/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/Postgres/api/graphql/src/index.ts +3 -6
- package/_templates/extensions/Postgres/api/graphql/src/web.ts +1 -1
- package/_templates/extensions/TenantStorages/ddb/api/graphql/src/index.ts +25 -0
- package/_templates/extensions/TenantStorages/ddb/api/graphql/src/web.ts +17 -0
- package/_templates/extensions/TenantStorages/ddb-os/api/graphql/src/index.ts +25 -0
- package/_templates/extensions/TenantStorages/ddb-os/api/graphql/src/web.ts +17 -0
- package/_templates/extensions/TenantStorages/pg/api/graphql/src/index.ts +25 -0
- package/_templates/extensions/TenantStorages/pg/api/graphql/src/web.ts +16 -0
- package/api.d.ts +6 -6
- package/api.js +3 -2
- package/api.js.map +1 -1
- package/decorators/GetPulumiServiceWithDownloadInfo.d.ts +1 -3
- package/decorators/GetPulumiServiceWithDownloadInfo.js +15 -11
- package/decorators/GetPulumiServiceWithDownloadInfo.js.map +1 -1
- package/extensions/AuroraPostgresCluster.d.ts +12 -0
- package/extensions/{Postgres.js → AuroraPostgresCluster.js} +7 -7
- package/extensions/AuroraPostgresCluster.js.map +1 -0
- package/extensions/OpenSearch/ReplaceApiLambdaFnHandlers.d.ts +3 -2
- package/extensions/OpenSearch/ReplaceApiLambdaFnHandlers.js +7 -3
- package/extensions/OpenSearch/ReplaceApiLambdaFnHandlers.js.map +1 -1
- package/extensions/Postgres/AddCorePostgres.d.ts +1 -1
- package/extensions/Postgres/AddCorePostgres.js +0 -2
- package/extensions/Postgres/AddCorePostgres.js.map +1 -1
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.d.ts +4 -3
- package/extensions/Postgres/CopyPgModulesAfterApiBuild.js.map +1 -1
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.d.ts +6 -5
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js +6 -2
- package/extensions/Postgres/ReplaceApiLambdaFnHandlers.js.map +1 -1
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.d.ts +1 -1
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js +8 -10
- package/extensions/Postgres/ValidatePostgresBeforeCoreDeploy.js.map +1 -1
- package/extensions/Postgres/assertPostgresNetwork.d.ts +19 -0
- package/extensions/Postgres/assertPostgresNetwork.js +16 -0
- package/extensions/Postgres/assertPostgresNetwork.js.map +1 -0
- package/extensions/Postgres/copyPgRuntimeModules.d.ts +1 -1
- package/extensions/Postgres/copyPgRuntimeModules.js +2 -2
- package/extensions/Postgres/copyPgRuntimeModules.js.map +1 -1
- package/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.d.ts +17 -2
- package/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.js +26 -19
- package/extensions/ProjectAws/AutoInstall/AutoInstallAfterApiDeploy.js.map +1 -1
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.d.ts +2 -2
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js +1 -1
- package/extensions/ProjectAws/EnsurePostgresSetupUnchanged.js.map +1 -1
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.d.ts +3 -3
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js +1 -1
- package/extensions/ProjectAws/RefuseApiWatchWithPostgres.js.map +1 -1
- package/extensions/ProjectAws/TenantStorages/AddTenantStorages.d.ts +34 -0
- package/extensions/ProjectAws/TenantStorages/AddTenantStorages.js +55 -0
- package/extensions/ProjectAws/TenantStorages/AddTenantStorages.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.d.ts +26 -0
- package/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.js +49 -0
- package/extensions/ProjectAws/TenantStorages/ApplyTenantStoragesApiEntry.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/CopyPgModulesForTenantStorages.d.ts +17 -0
- package/extensions/ProjectAws/TenantStorages/CopyPgModulesForTenantStorages.js +26 -0
- package/extensions/ProjectAws/TenantStorages/CopyPgModulesForTenantStorages.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/EnsureStoragesNotRemoved.d.ts +41 -0
- package/extensions/ProjectAws/TenantStorages/EnsureStoragesNotRemoved.js +55 -0
- package/extensions/ProjectAws/TenantStorages/EnsureStoragesNotRemoved.js.map +1 -0
- package/extensions/ProjectAws/TenantStorages/ValidateTenantStoragesBeforeCoreDeploy.d.ts +48 -0
- package/extensions/ProjectAws/TenantStorages/ValidateTenantStoragesBeforeCoreDeploy.js +78 -0
- package/extensions/ProjectAws/TenantStorages/ValidateTenantStoragesBeforeCoreDeploy.js.map +1 -0
- package/extensions/ProjectAws.js +11 -1
- package/extensions/ProjectAws.js.map +1 -1
- package/extensions/definitions.js +2 -4
- package/extensions/definitions.js.map +1 -1
- package/extensions/index.d.ts +3 -3
- package/extensions/index.js +3 -4
- package/extensions/registerExtensionImplementations.js +3 -5
- package/extensions/registerExtensionImplementations.js.map +1 -1
- package/infra.d.ts +13 -8
- package/infra.js +9 -10
- package/infra.js.map +1 -1
- package/package.json +19 -18
- package/project.d.ts +4 -2
- package/pulumi/apps/admin/createAdminPulumiApp.js.map +1 -1
- package/pulumi/apps/api/ApiGraphql.js.map +1 -1
- package/pulumi/apps/api/ApiGraphqlWeb.js.map +1 -1
- package/pulumi/apps/api/ApiOutput.js.map +1 -1
- package/pulumi/apps/api/ApiSchemaSetup.d.ts +35 -13
- package/pulumi/apps/api/ApiSchemaSetup.js +31 -8
- package/pulumi/apps/api/ApiSchemaSetup.js.map +1 -1
- package/pulumi/apps/api/apiDynamoDb.js.map +1 -1
- package/pulumi/apps/api/backgroundTask/types.js.map +1 -1
- package/pulumi/apps/api/createApiPulumiApp.js +14 -7
- package/pulumi/apps/api/createApiPulumiApp.js.map +1 -1
- package/pulumi/apps/common/CoreOutput.d.ts +11 -0
- package/pulumi/apps/common/CoreOutput.js +2 -1
- package/pulumi/apps/common/CoreOutput.js.map +1 -1
- package/pulumi/apps/core/CoreCognito.d.ts +14 -0
- package/pulumi/apps/core/CoreCognito.js +34 -1
- package/pulumi/apps/core/CoreCognito.js.map +1 -1
- package/pulumi/apps/core/CorePostgres.d.ts +6 -4
- package/pulumi/apps/core/CorePostgres.js +26 -20
- package/pulumi/apps/core/CorePostgres.js.map +1 -1
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js +11 -0
- package/pulumi/apps/core/cognitoIdentityProviders/configure.js.map +1 -1
- package/pulumi/apps/core/coreDynamoDb.d.ts +2 -2
- package/pulumi/apps/core/coreDynamoDb.js.map +1 -1
- package/pulumi/apps/core/coreServiceManifests.d.ts +6 -4
- package/pulumi/apps/core/coreServiceManifests.js.map +1 -1
- package/pulumi/apps/core/coreVpcEndpoints.d.ts +9 -2
- package/pulumi/apps/core/coreVpcEndpoints.js +15 -11
- package/pulumi/apps/core/coreVpcEndpoints.js.map +1 -1
- package/pulumi/apps/core/createCorePulumiApp.js +8 -1
- package/pulumi/apps/core/createCorePulumiApp.js.map +1 -1
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.d.ts +4 -2
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js +4 -3
- package/pulumi/apps/extensions/getPostgresConfigFromExtension.js.map +1 -1
- package/pulumi/apps/extensions/getTenantStoragesFromExtension.d.ts +19 -0
- package/pulumi/apps/extensions/getTenantStoragesFromExtension.js +32 -0
- package/pulumi/apps/extensions/getTenantStoragesFromExtension.js.map +1 -0
- package/pulumi/apps/extensions/projectUsesPostgres.d.ts +1 -1
- package/pulumi/apps/extensions/projectUsesPostgres.js.map +1 -1
- package/pulumi/apps/react/adminSettingsItem.d.ts +1 -1
- package/pulumi/apps/react/adminSettingsItem.js.map +1 -1
- package/pulumi/apps/react/createReactPulumiApp.js.map +1 -1
- package/pulumi/extensions/index.d.ts +8 -0
- package/pulumi/extensions/index.js +2 -1
- package/pulumi/extensions/index.js.map +1 -1
- package/pulumi/types.d.ts +2 -2
- package/pulumi/utils/lambdaEnvVariables.js +2 -2
- package/pulumi/utils/lambdaEnvVariables.js.map +1 -1
- package/pulumi/utils/withServiceManifest.d.ts +2 -2
- package/pulumi/utils/withServiceManifest.js.map +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js +1 -1
- package/services/PulumiGetStackOutputService/mapStackOutput.js.map +1 -1
- package/extensions/Postgres.d.ts +0 -11
- package/extensions/Postgres.js.map +0 -1
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.d.ts +0 -14
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.js +0 -23
- package/extensions/RdsProxy/EnsurePostgresWithRdsProxy.js.map +0 -1
- package/extensions/RdsProxy.d.ts +0 -9
- package/extensions/RdsProxy.js +0 -31
- package/extensions/RdsProxy.js.map +0 -1
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.d.ts +0 -5
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.js +0 -8
- package/pulumi/apps/extensions/getRdsProxyConfigFromExtension.js.map +0 -1
|
@@ -16,12 +16,14 @@ export interface CorePostgresParams {
|
|
|
16
16
|
network: PostgresNetwork;
|
|
17
17
|
protect: boolean;
|
|
18
18
|
getEngineVersion?: () => pulumi.Input<string>;
|
|
19
|
+
namePrefix?: string;
|
|
20
|
+
description?: string;
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
|
-
* The Postgres database of a project with `<Infra.
|
|
22
|
-
* v2 cluster with a writer and `readers` reader instances, and its credentials in a
|
|
23
|
-
* secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it,
|
|
24
|
-
* same secret.
|
|
23
|
+
* The Postgres database of a project with `<Infra.AuroraPostgres />`: an Aurora PostgreSQL 17
|
|
24
|
+
* Serverless v2 cluster with a writer and `readers` reader instances, and its credentials in a
|
|
25
|
+
* Secrets Manager secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it,
|
|
26
|
+
* which reads the same secret.
|
|
25
27
|
*
|
|
26
28
|
* The cluster, its instances and the proxy go into `network`: the private subnets of the VPC the
|
|
27
29
|
* core app creates and its default security group, which the API functions use too, or the
|
|
@@ -30,17 +30,21 @@ const CorePostgres = createAppModule({
|
|
|
30
30
|
config (app, params) {
|
|
31
31
|
const { network, protect } = params;
|
|
32
32
|
const getEngineVersion = params.getEngineVersion ?? getLatestEngineVersion;
|
|
33
|
+
const prefix = params.namePrefix ?? "";
|
|
34
|
+
const name = (value)=>`${prefix}${value}`;
|
|
35
|
+
const database = params.description ?? "the Webiny Postgres database";
|
|
36
|
+
const Database = database.charAt(0).toUpperCase() + database.slice(1);
|
|
33
37
|
const password = app.addResource(__rspack_external__pulumi_random_073a0f72.RandomPassword, {
|
|
34
|
-
name: "pg-db-password",
|
|
38
|
+
name: name("pg-db-password"),
|
|
35
39
|
config: {
|
|
36
40
|
length: 32,
|
|
37
41
|
special: false
|
|
38
42
|
}
|
|
39
43
|
});
|
|
40
44
|
const secret = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.secretsmanager.Secret, {
|
|
41
|
-
name: "pg-db",
|
|
45
|
+
name: name("pg-db"),
|
|
42
46
|
config: {
|
|
43
|
-
description:
|
|
47
|
+
description: `Credentials of ${database}.`,
|
|
44
48
|
recoveryWindowInDays: protect ? 7 : 0
|
|
45
49
|
},
|
|
46
50
|
opts: {
|
|
@@ -48,7 +52,7 @@ const CorePostgres = createAppModule({
|
|
|
48
52
|
}
|
|
49
53
|
});
|
|
50
54
|
app.addResource(__rspack_external__pulumi_aws_9e2bee2d.secretsmanager.SecretVersion, {
|
|
51
|
-
name: "pg-db",
|
|
55
|
+
name: name("pg-db"),
|
|
52
56
|
config: {
|
|
53
57
|
secretId: secret.output.id,
|
|
54
58
|
secretString: __rspack_external__pulumi_pulumi_f3e773ed.all([
|
|
@@ -60,17 +64,17 @@ const CorePostgres = createAppModule({
|
|
|
60
64
|
}
|
|
61
65
|
});
|
|
62
66
|
const subnetGroup = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.SubnetGroup, {
|
|
63
|
-
name: "pg-db",
|
|
67
|
+
name: name("pg-db"),
|
|
64
68
|
config: {
|
|
65
|
-
description:
|
|
69
|
+
description: `Subnets of ${database}.`,
|
|
66
70
|
subnetIds: network.subnetIds
|
|
67
71
|
}
|
|
68
72
|
});
|
|
69
73
|
const parameterGroup = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.ClusterParameterGroup, {
|
|
70
|
-
name: "pg-db",
|
|
74
|
+
name: name("pg-db"),
|
|
71
75
|
config: {
|
|
72
76
|
family: PARAMETER_GROUP_FAMILY,
|
|
73
|
-
description:
|
|
77
|
+
description: `${Database}: TCP keepalives.`,
|
|
74
78
|
parameters: [
|
|
75
79
|
{
|
|
76
80
|
name: "tcp_keepalives_idle",
|
|
@@ -88,13 +92,13 @@ const CorePostgres = createAppModule({
|
|
|
88
92
|
}
|
|
89
93
|
});
|
|
90
94
|
const finalSnapshotSuffix = protect ? app.addResource(__rspack_external__pulumi_random_073a0f72.RandomId, {
|
|
91
|
-
name: "pg-db-final-snapshot",
|
|
95
|
+
name: name("pg-db-final-snapshot"),
|
|
92
96
|
config: {
|
|
93
97
|
byteLength: 4
|
|
94
98
|
}
|
|
95
99
|
}) : null;
|
|
96
100
|
const cluster = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.Cluster, {
|
|
97
|
-
name: "pg-db",
|
|
101
|
+
name: name("pg-db"),
|
|
98
102
|
config: {
|
|
99
103
|
engine: ENGINE,
|
|
100
104
|
engineMode: "provisioned",
|
|
@@ -117,9 +121,10 @@ const CorePostgres = createAppModule({
|
|
|
117
121
|
],
|
|
118
122
|
copyTagsToSnapshot: true,
|
|
119
123
|
deletionProtection: protect,
|
|
120
|
-
backupRetentionPeriod: protect ?
|
|
124
|
+
backupRetentionPeriod: protect ? 35 : 1,
|
|
125
|
+
deleteAutomatedBackups: protect ? false : void 0,
|
|
121
126
|
skipFinalSnapshot: !protect,
|
|
122
|
-
finalSnapshotIdentifier: finalSnapshotSuffix ? __rspack_external__pulumi_pulumi_f3e773ed.interpolate`webiny
|
|
127
|
+
finalSnapshotIdentifier: finalSnapshotSuffix ? __rspack_external__pulumi_pulumi_f3e773ed.interpolate`webiny-${prefix}pg-final-${finalSnapshotSuffix.output.hex}` : void 0,
|
|
123
128
|
applyImmediately: true
|
|
124
129
|
},
|
|
125
130
|
opts: {
|
|
@@ -133,7 +138,7 @@ const CorePostgres = createAppModule({
|
|
|
133
138
|
for(let index = 0; index <= params.readers; index++){
|
|
134
139
|
const isWriter = 0 === index;
|
|
135
140
|
instances.push(app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.ClusterInstance, {
|
|
136
|
-
name: isWriter ? "pg-db-writer" : `pg-db-reader-${index}
|
|
141
|
+
name: name(isWriter ? "pg-db-writer" : `pg-db-reader-${index}`),
|
|
137
142
|
config: {
|
|
138
143
|
clusterIdentifier: cluster.output.id,
|
|
139
144
|
instanceClass: "db.serverless",
|
|
@@ -156,7 +161,8 @@ const CorePostgres = createAppModule({
|
|
|
156
161
|
secret,
|
|
157
162
|
cluster,
|
|
158
163
|
instances,
|
|
159
|
-
network
|
|
164
|
+
network,
|
|
165
|
+
prefix
|
|
160
166
|
});
|
|
161
167
|
return {
|
|
162
168
|
cluster,
|
|
@@ -180,15 +186,15 @@ const CorePostgres = createAppModule({
|
|
|
180
186
|
}
|
|
181
187
|
});
|
|
182
188
|
function addProxy(app, params) {
|
|
183
|
-
const { secret, cluster, instances, network } = params;
|
|
189
|
+
const { secret, cluster, instances, network, prefix } = params;
|
|
184
190
|
const role = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.iam.Role, {
|
|
185
|
-
name:
|
|
191
|
+
name: `${prefix}pg-proxy`,
|
|
186
192
|
config: {
|
|
187
193
|
assumeRolePolicy: assumeRolePolicy("rds.amazonaws.com")
|
|
188
194
|
}
|
|
189
195
|
});
|
|
190
196
|
app.addResource(__rspack_external__pulumi_aws_9e2bee2d.iam.RolePolicy, {
|
|
191
|
-
name:
|
|
197
|
+
name: `${prefix}pg-proxy`,
|
|
192
198
|
config: {
|
|
193
199
|
role: role.output.id,
|
|
194
200
|
policy: __rspack_external__pulumi_pulumi_f3e773ed.all([
|
|
@@ -210,7 +216,7 @@ function addProxy(app, params) {
|
|
|
210
216
|
}
|
|
211
217
|
});
|
|
212
218
|
const proxy = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.Proxy, {
|
|
213
|
-
name:
|
|
219
|
+
name: `${prefix}pg-proxy`,
|
|
214
220
|
config: {
|
|
215
221
|
engineFamily: "POSTGRESQL",
|
|
216
222
|
auths: [
|
|
@@ -229,7 +235,7 @@ function addProxy(app, params) {
|
|
|
229
235
|
}
|
|
230
236
|
});
|
|
231
237
|
const targetGroup = app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.ProxyDefaultTargetGroup, {
|
|
232
|
-
name:
|
|
238
|
+
name: `${prefix}pg-proxy`,
|
|
233
239
|
config: {
|
|
234
240
|
dbProxyName: proxy.output.name,
|
|
235
241
|
connectionPoolConfig: {
|
|
@@ -240,7 +246,7 @@ function addProxy(app, params) {
|
|
|
240
246
|
}
|
|
241
247
|
});
|
|
242
248
|
app.addResource(__rspack_external__pulumi_aws_9e2bee2d.rds.ProxyTarget, {
|
|
243
|
-
name:
|
|
249
|
+
name: `${prefix}pg-proxy`,
|
|
244
250
|
config: {
|
|
245
251
|
dbProxyName: proxy.output.name,
|
|
246
252
|
targetGroupName: targetGroup.output.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/CorePostgres.js","sources":["../../../../src/pulumi/apps/core/CorePostgres.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as random from \"@pulumi/random\";\nimport {\n createAppModule,\n type PulumiApp,\n type PulumiAppModule,\n type PulumiAppResource\n} from \"@webiny/pulumi\";\n\nexport type CorePostgres = PulumiAppModule<typeof CorePostgres>;\n\nexport const POSTGRES_DATABASE = \"webiny\";\nexport const POSTGRES_USER = \"webiny\";\nexport const POSTGRES_PORT = 5432;\n\n/* Aurora PostgreSQL's major version, and its cluster parameter group family. */\nconst ENGINE = \"aurora-postgresql\";\nconst ENGINE_MAJOR_VERSION = \"17\";\nconst PARAMETER_GROUP_FAMILY = \"aurora-postgresql17\";\n\nexport interface PostgresNetwork {\n subnetIds: pulumi.Input<pulumi.Input<string>[]>;\n securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;\n}\n\nexport interface CorePostgresParams {\n minCapacity: number;\n maxCapacity: number;\n readers: number;\n rdsProxy: boolean;\n network: PostgresNetwork;\n /* On in production: deletion protection, a week of backups and a final snapshot. */\n protect: boolean;\n /*\n * The engine version a new cluster gets: the latest 17.x. Replaced in tests, where there is no\n * AWS to ask.\n */\n getEngineVersion?: () => pulumi.Input<string>;\n}\n\nconst getLatestEngineVersion = () => {\n return pulumi.output(\n aws.rds.getEngineVersion({ engine: ENGINE, version: ENGINE_MAJOR_VERSION, latest: true })\n ).versionActual;\n};\n\nconst assumeRolePolicy = (service: string) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [{ Effect: \"Allow\", Principal: { Service: service }, Action: \"sts:AssumeRole\" }]\n });\n\n/**\n * The Postgres database of a project with `<Infra.Postgres />`: an Aurora PostgreSQL 17 Serverless\n * v2 cluster with a writer and `readers` reader instances, and its credentials in a Secrets Manager\n * secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it, which reads the\n * same secret.\n *\n * The cluster, its instances and the proxy go into `network`: the private subnets of the VPC the\n * core app creates and its default security group, which the API functions use too, or the\n * `postgresVpcConfig` of an existing VPC.\n *\n * No password leaves this module: the API reads it from the secret.\n */\nexport const CorePostgres = createAppModule({\n name: \"CorePostgres\",\n config(app: PulumiApp, params: CorePostgresParams) {\n const { network, protect } = params;\n const getEngineVersion = params.getEngineVersion ?? getLatestEngineVersion;\n\n const password = app.addResource(random.RandomPassword, {\n name: \"pg-db-password\",\n config: { length: 32, special: false }\n });\n\n const secret = app.addResource(aws.secretsmanager.Secret, {\n name: \"pg-db\",\n config: {\n description: \"Credentials of the Webiny Postgres database.\",\n // Outside production, a destroyed project can be deployed again at once.\n recoveryWindowInDays: protect ? 7 : 0\n },\n opts: { protect }\n });\n\n app.addResource(aws.secretsmanager.SecretVersion, {\n name: \"pg-db\",\n config: {\n secretId: secret.output.id,\n secretString: pulumi\n .all([password.output.result])\n .apply(([value]) =>\n JSON.stringify({ username: POSTGRES_USER, password: value })\n )\n }\n });\n\n const subnetGroup = app.addResource(aws.rds.SubnetGroup, {\n name: \"pg-db\",\n config: {\n description: \"Subnets of the Webiny Postgres database.\",\n subnetIds: network.subnetIds\n }\n });\n\n /*\n * The server notices a client that went away without closing its connection (a Lambda\n * environment that was recycled) within about two minutes, and frees the connection.\n */\n const parameterGroup = app.addResource(aws.rds.ClusterParameterGroup, {\n name: \"pg-db\",\n config: {\n family: PARAMETER_GROUP_FAMILY,\n description: \"Webiny Postgres database: TCP keepalives.\",\n parameters: [\n { name: \"tcp_keepalives_idle\", value: \"60\" },\n { name: \"tcp_keepalives_interval\", value: \"10\" },\n { name: \"tcp_keepalives_count\", value: \"6\" }\n ]\n }\n });\n\n // A final snapshot needs a name that no earlier snapshot of the account has.\n const finalSnapshotSuffix = protect\n ? app.addResource(random.RandomId, {\n name: \"pg-db-final-snapshot\",\n config: { byteLength: 4 }\n })\n : null;\n\n const cluster = app.addResource(aws.rds.Cluster, {\n name: \"pg-db\",\n config: {\n engine: ENGINE,\n engineMode: \"provisioned\",\n engineVersion: getEngineVersion(),\n databaseName: POSTGRES_DATABASE,\n masterUsername: POSTGRES_USER,\n masterPassword: password.output.result,\n port: POSTGRES_PORT,\n storageType: \"aurora\",\n storageEncrypted: true,\n dbSubnetGroupName: subnetGroup.output.name,\n dbClusterParameterGroupName: parameterGroup.output.name,\n vpcSecurityGroupIds: network.securityGroupIds,\n serverlessv2ScalingConfiguration: {\n minCapacity: params.minCapacity,\n maxCapacity: params.maxCapacity\n },\n enabledCloudwatchLogsExports: [\"postgresql\"],\n copyTagsToSnapshot: true,\n deletionProtection: protect,\n backupRetentionPeriod: protect ? 7 : 1,\n skipFinalSnapshot: !protect,\n finalSnapshotIdentifier: finalSnapshotSuffix\n ? pulumi.interpolate`webiny-pg-final-${finalSnapshotSuffix.output.hex}`\n : undefined,\n // Capacity changes apply now, not in the next maintenance window.\n applyImmediately: true\n },\n opts: {\n protect,\n // The version is picked when the cluster is created; AWS applies minor upgrades.\n // A newer 17.x must not make a later deploy upgrade the cluster.\n ignoreChanges: [\"engineVersion\"]\n }\n });\n\n const instances = [];\n for (let index = 0; index <= params.readers; index++) {\n const isWriter = index === 0;\n instances.push(\n app.addResource(aws.rds.ClusterInstance, {\n name: isWriter ? \"pg-db-writer\" : `pg-db-reader-${index}`,\n config: {\n clusterIdentifier: cluster.output.id,\n instanceClass: \"db.serverless\",\n engine: ENGINE,\n engineVersion: cluster.output.engineVersion,\n publiclyAccessible: false,\n performanceInsightsEnabled: true,\n // Readers in tier 0–1 scale with the writer, so a failover lands on a warm one.\n promotionTier: isWriter ? 0 : 1,\n applyImmediately: true\n },\n opts: { ignoreChanges: [\"engineVersion\"] }\n })\n );\n }\n\n let proxy: ReturnType<typeof addProxy> | null = null;\n if (params.rdsProxy) {\n proxy = addProxy(app, { secret, cluster, instances, network });\n }\n\n return {\n cluster,\n instances,\n secret,\n subnetGroup,\n parameterGroup,\n proxy: proxy?.proxy ?? null,\n outputs: {\n pgWriterHost: cluster.output.endpoint,\n pgReaderHost: cluster.output.readerEndpoint,\n ...(proxy ? { pgProxyHost: proxy.proxy.output.endpoint } : {}),\n pgPort: POSTGRES_PORT,\n pgDatabase: POSTGRES_DATABASE,\n pgUser: POSTGRES_USER,\n pgSecretArn: secret.output.arn\n }\n };\n }\n});\n\ninterface AddProxyParams {\n secret: PulumiAppResource<typeof aws.secretsmanager.Secret>;\n cluster: PulumiAppResource<typeof aws.rds.Cluster>;\n instances: PulumiAppResource<typeof aws.rds.ClusterInstance>[];\n network: PostgresNetwork;\n}\n\nfunction addProxy(app: PulumiApp, params: AddProxyParams) {\n const { secret, cluster, instances, network } = params;\n\n const role = app.addResource(aws.iam.Role, {\n name: \"pg-proxy\",\n config: { assumeRolePolicy: assumeRolePolicy(\"rds.amazonaws.com\") }\n });\n\n app.addResource(aws.iam.RolePolicy, {\n name: \"pg-proxy\",\n config: {\n role: role.output.id,\n policy: pulumi.all([secret.output.arn]).apply(([arn]) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [\n {\n Effect: \"Allow\",\n Action: [\"secretsmanager:GetSecretValue\"],\n Resource: [arn]\n }\n ]\n })\n )\n }\n });\n\n const proxy = app.addResource(aws.rds.Proxy, {\n name: \"pg-proxy\",\n config: {\n engineFamily: \"POSTGRESQL\",\n auths: [{ authScheme: \"SECRETS\", iamAuth: \"DISABLED\", secretArn: secret.output.arn }],\n roleArn: role.output.arn,\n vpcSubnetIds: network.subnetIds,\n vpcSecurityGroupIds: network.securityGroupIds,\n requireTls: true,\n idleClientTimeout: 900,\n debugLogging: false\n }\n });\n\n const targetGroup = app.addResource(aws.rds.ProxyDefaultTargetGroup, {\n name: \"pg-proxy\",\n config: {\n dbProxyName: proxy.output.name,\n connectionPoolConfig: {\n maxConnectionsPercent: 70,\n maxIdleConnectionsPercent: 50,\n connectionBorrowTimeout: 10\n }\n }\n });\n\n app.addResource(aws.rds.ProxyTarget, {\n name: \"pg-proxy\",\n config: {\n dbProxyName: proxy.output.name,\n targetGroupName: targetGroup.output.name,\n dbClusterIdentifier: cluster.output.id\n },\n // The proxy can only register a cluster whose instances are available.\n opts: { dependsOn: instances.map(instance => instance.output) }\n });\n\n return { role, proxy, targetGroup };\n}\n"],"names":["POSTGRES_DATABASE","POSTGRES_USER","POSTGRES_PORT","ENGINE","ENGINE_MAJOR_VERSION","PARAMETER_GROUP_FAMILY","getLatestEngineVersion","pulumi","aws","assumeRolePolicy","service","JSON","CorePostgres","createAppModule","app","params","network","protect","getEngineVersion","password","random","secret","value","subnetGroup","parameterGroup","finalSnapshotSuffix","cluster","undefined","instances","index","isWriter","proxy","addProxy","role","arn","targetGroup","instance"],"mappings":";;;;AAYO,MAAMA,oBAAoB;AAC1B,MAAMC,gBAAgB;AACtB,MAAMC,gBAAgB;AAG7B,MAAMC,SAAS;AACf,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;AAsB/B,MAAMC,yBAAyB,IACpBC,0CAAAA,MAAa,CAChBC,uCAAAA,GAAAA,CAAAA,gBAAwB,CAAC;QAAE,QAAQL;QAAQ,SAASC;QAAsB,QAAQ;IAAK,IACzF,aAAa;AAGnB,MAAMK,mBAAmB,CAACC,UACtBC,KAAK,SAAS,CAAC;QACX,SAAS;QACT,WAAW;YAAC;gBAAE,QAAQ;gBAAS,WAAW;oBAAE,SAASD;gBAAQ;gBAAG,QAAQ;YAAiB;SAAE;IAC/F;AAcG,MAAME,eAAeC,gBAAgB;IACxC,MAAM;IACN,QAAOC,GAAc,EAAEC,MAA0B;QAC7C,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;QAC7B,MAAMG,mBAAmBH,OAAO,gBAAgB,IAAIT;QAEpD,MAAMa,WAAWL,IAAI,WAAW,CAACM,0CAAAA,cAAqB,EAAE;YACpD,MAAM;YACN,QAAQ;gBAAE,QAAQ;gBAAI,SAAS;YAAM;QACzC;QAEA,MAAMC,SAASP,IAAI,WAAW,CAACN,uCAAAA,cAAAA,CAAAA,MAAyB,EAAE;YACtD,MAAM;YACN,QAAQ;gBACJ,aAAa;gBAEb,sBAAsBS,UAAU,IAAI;YACxC;YACA,MAAM;gBAAEA;YAAQ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GAAAA,CAAAA,uBAA+B,EAAE;QACjE,MAAM;QACN,QAAQ;YACJ,aAAauB,MAAM,MAAM,CAAC,IAAI;YAC9B,sBAAsB;gBAClB,uBAAuB;gBACvB,2BAA2B;gBAC3B,yBAAyB;YAC7B;QACJ;IACJ;IAEAjB,IAAI,WAAW,CAACN,uCAAAA,GAAAA,CAAAA,WAAmB,EAAE;QACjC,MAAM;QACN,QAAQ;YACJ,aAAauB,MAAM,MAAM,CAAC,IAAI;YAC9B,iBAAiBI,YAAY,MAAM,CAAC,IAAI;YACxC,qBAAqBT,QAAQ,MAAM,CAAC,EAAE;QAC1C;QAEA,MAAM;YAAE,WAAWE,UAAU,GAAG,CAACQ,CAAAA,WAAYA,SAAS,MAAM;QAAE;IAClE;IAEA,OAAO;QAAEH;QAAMF;QAAOI;IAAY;AACtC"}
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/CorePostgres.js","sources":["../../../../src/pulumi/apps/core/CorePostgres.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport * as random from \"@pulumi/random\";\nimport {\n createAppModule,\n type PulumiApp,\n type PulumiAppModule,\n type PulumiAppResource\n} from \"@webiny/pulumi\";\n\nexport type CorePostgres = PulumiAppModule<typeof CorePostgres>;\n\nexport const POSTGRES_DATABASE = \"webiny\";\nexport const POSTGRES_USER = \"webiny\";\nexport const POSTGRES_PORT = 5432;\n\n/* Aurora PostgreSQL's major version, and its cluster parameter group family. */\nconst ENGINE = \"aurora-postgresql\";\nconst ENGINE_MAJOR_VERSION = \"17\";\nconst PARAMETER_GROUP_FAMILY = \"aurora-postgresql17\";\n\nexport interface PostgresNetwork {\n subnetIds: pulumi.Input<pulumi.Input<string>[]>;\n securityGroupIds: pulumi.Input<pulumi.Input<string>[]>;\n}\n\nexport interface CorePostgresParams {\n minCapacity: number;\n maxCapacity: number;\n readers: number;\n rdsProxy: boolean;\n network: PostgresNetwork;\n /*\n * On in production: deletion protection, 35 days of backups that outlive the cluster, and a\n * final snapshot.\n */\n protect: boolean;\n /*\n * The engine version a new cluster gets: the latest 17.x. Replaced in tests, where there is no\n * AWS to ask.\n */\n getEngineVersion?: () => pulumi.Input<string>;\n /*\n * Put before the name of every resource, so a project can have several clusters: none for the\n * cluster of `<Infra.AuroraPostgres />`, `storage-<id>-` for each `<Infra.TenantStorage.AuroraPostgres>`.\n * It is part of the resources' Pulumi names, so it can't change once a cluster is deployed.\n */\n namePrefix?: string;\n /* What the secret and the database's AWS descriptions call it. Default: \"the Webiny Postgres database\". */\n description?: string;\n}\n\nconst getLatestEngineVersion = () => {\n return pulumi.output(\n aws.rds.getEngineVersion({ engine: ENGINE, version: ENGINE_MAJOR_VERSION, latest: true })\n ).versionActual;\n};\n\nconst assumeRolePolicy = (service: string) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [{ Effect: \"Allow\", Principal: { Service: service }, Action: \"sts:AssumeRole\" }]\n });\n\n/**\n * The Postgres database of a project with `<Infra.AuroraPostgres />`: an Aurora PostgreSQL 17\n * Serverless v2 cluster with a writer and `readers` reader instances, and its credentials in a\n * Secrets Manager secret (`{ username, password }`). With `rdsProxy`, an RDS Proxy in front of it,\n * which reads the same secret.\n *\n * The cluster, its instances and the proxy go into `network`: the private subnets of the VPC the\n * core app creates and its default security group, which the API functions use too, or the\n * `postgresVpcConfig` of an existing VPC.\n *\n * No password leaves this module: the API reads it from the secret.\n */\nexport const CorePostgres = createAppModule({\n name: \"CorePostgres\",\n config(app: PulumiApp, params: CorePostgresParams) {\n const { network, protect } = params;\n const getEngineVersion = params.getEngineVersion ?? getLatestEngineVersion;\n const prefix = params.namePrefix ?? \"\";\n const name = (value: string) => `${prefix}${value}`;\n const database = params.description ?? \"the Webiny Postgres database\";\n const Database = database.charAt(0).toUpperCase() + database.slice(1);\n\n const password = app.addResource(random.RandomPassword, {\n name: name(\"pg-db-password\"),\n config: { length: 32, special: false }\n });\n\n const secret = app.addResource(aws.secretsmanager.Secret, {\n name: name(\"pg-db\"),\n config: {\n description: `Credentials of ${database}.`,\n // Outside production, a destroyed project can be deployed again at once.\n recoveryWindowInDays: protect ? 7 : 0\n },\n opts: { protect }\n });\n\n app.addResource(aws.secretsmanager.SecretVersion, {\n name: name(\"pg-db\"),\n config: {\n secretId: secret.output.id,\n secretString: pulumi\n .all([password.output.result])\n .apply(([value]) =>\n JSON.stringify({ username: POSTGRES_USER, password: value })\n )\n }\n });\n\n const subnetGroup = app.addResource(aws.rds.SubnetGroup, {\n name: name(\"pg-db\"),\n config: {\n description: `Subnets of ${database}.`,\n subnetIds: network.subnetIds\n }\n });\n\n /*\n * The server notices a client that went away without closing its connection (a Lambda\n * environment that was recycled) within about two minutes, and frees the connection.\n */\n const parameterGroup = app.addResource(aws.rds.ClusterParameterGroup, {\n name: name(\"pg-db\"),\n config: {\n family: PARAMETER_GROUP_FAMILY,\n description: `${Database}: TCP keepalives.`,\n parameters: [\n { name: \"tcp_keepalives_idle\", value: \"60\" },\n { name: \"tcp_keepalives_interval\", value: \"10\" },\n { name: \"tcp_keepalives_count\", value: \"6\" }\n ]\n }\n });\n\n // A final snapshot needs a name that no earlier snapshot of the account has.\n const finalSnapshotSuffix = protect\n ? app.addResource(random.RandomId, {\n name: name(\"pg-db-final-snapshot\"),\n config: { byteLength: 4 }\n })\n : null;\n\n const cluster = app.addResource(aws.rds.Cluster, {\n name: name(\"pg-db\"),\n config: {\n engine: ENGINE,\n engineMode: \"provisioned\",\n engineVersion: getEngineVersion(),\n databaseName: POSTGRES_DATABASE,\n masterUsername: POSTGRES_USER,\n masterPassword: password.output.result,\n port: POSTGRES_PORT,\n storageType: \"aurora\",\n storageEncrypted: true,\n dbSubnetGroupName: subnetGroup.output.name,\n dbClusterParameterGroupName: parameterGroup.output.name,\n vpcSecurityGroupIds: network.securityGroupIds,\n serverlessv2ScalingConfiguration: {\n minCapacity: params.minCapacity,\n maxCapacity: params.maxCapacity\n },\n enabledCloudwatchLogsExports: [\"postgresql\"],\n copyTagsToSnapshot: true,\n deletionProtection: protect,\n // Point-in-time restore is always on in Aurora; this is its window. Production\n // keeps the maximum, 35 days, the same as DynamoDB's point-in-time recovery.\n // Backup storage up to the cluster volume's size is free. Elsewhere, 1 day.\n backupRetentionPeriod: protect ? 35 : 1,\n // Production keeps its automated backups when the cluster is deleted, so it can\n // still be restored to a point in time until the window runs out. The first day is\n // free, later days are billed, and a region holds at most 40 retained automated\n // backups. Elsewhere the default (true) applies: a destroyed environment leaves\n // nothing behind.\n deleteAutomatedBackups: protect ? false : undefined,\n skipFinalSnapshot: !protect,\n finalSnapshotIdentifier: finalSnapshotSuffix\n ? pulumi.interpolate`webiny-${prefix}pg-final-${finalSnapshotSuffix.output.hex}`\n : undefined,\n // Capacity changes apply now, not in the next maintenance window.\n applyImmediately: true\n },\n opts: {\n protect,\n // The version is picked when the cluster is created; AWS applies minor upgrades.\n // A newer 17.x must not make a later deploy upgrade the cluster.\n ignoreChanges: [\"engineVersion\"]\n }\n });\n\n const instances = [];\n for (let index = 0; index <= params.readers; index++) {\n const isWriter = index === 0;\n instances.push(\n app.addResource(aws.rds.ClusterInstance, {\n name: name(isWriter ? \"pg-db-writer\" : `pg-db-reader-${index}`),\n config: {\n clusterIdentifier: cluster.output.id,\n instanceClass: \"db.serverless\",\n engine: ENGINE,\n engineVersion: cluster.output.engineVersion,\n publiclyAccessible: false,\n performanceInsightsEnabled: true,\n // Readers in tier 0–1 scale with the writer, so a failover lands on a warm one.\n promotionTier: isWriter ? 0 : 1,\n applyImmediately: true\n },\n opts: { ignoreChanges: [\"engineVersion\"] }\n })\n );\n }\n\n let proxy: ReturnType<typeof addProxy> | null = null;\n if (params.rdsProxy) {\n proxy = addProxy(app, { secret, cluster, instances, network, prefix });\n }\n\n return {\n cluster,\n instances,\n secret,\n subnetGroup,\n parameterGroup,\n proxy: proxy?.proxy ?? null,\n outputs: {\n pgWriterHost: cluster.output.endpoint,\n pgReaderHost: cluster.output.readerEndpoint,\n ...(proxy ? { pgProxyHost: proxy.proxy.output.endpoint } : {}),\n pgPort: POSTGRES_PORT,\n pgDatabase: POSTGRES_DATABASE,\n pgUser: POSTGRES_USER,\n pgSecretArn: secret.output.arn\n }\n };\n }\n});\n\ninterface AddProxyParams {\n secret: PulumiAppResource<typeof aws.secretsmanager.Secret>;\n cluster: PulumiAppResource<typeof aws.rds.Cluster>;\n instances: PulumiAppResource<typeof aws.rds.ClusterInstance>[];\n network: PostgresNetwork;\n prefix: string;\n}\n\nfunction addProxy(app: PulumiApp, params: AddProxyParams) {\n const { secret, cluster, instances, network, prefix } = params;\n\n const role = app.addResource(aws.iam.Role, {\n name: `${prefix}pg-proxy`,\n config: { assumeRolePolicy: assumeRolePolicy(\"rds.amazonaws.com\") }\n });\n\n app.addResource(aws.iam.RolePolicy, {\n name: `${prefix}pg-proxy`,\n config: {\n role: role.output.id,\n policy: pulumi.all([secret.output.arn]).apply(([arn]) =>\n JSON.stringify({\n Version: \"2012-10-17\",\n Statement: [\n {\n Effect: \"Allow\",\n Action: [\"secretsmanager:GetSecretValue\"],\n Resource: [arn]\n }\n ]\n })\n )\n }\n });\n\n const proxy = app.addResource(aws.rds.Proxy, {\n name: `${prefix}pg-proxy`,\n config: {\n engineFamily: \"POSTGRESQL\",\n auths: [{ authScheme: \"SECRETS\", iamAuth: \"DISABLED\", secretArn: secret.output.arn }],\n roleArn: role.output.arn,\n vpcSubnetIds: network.subnetIds,\n vpcSecurityGroupIds: network.securityGroupIds,\n requireTls: true,\n idleClientTimeout: 900,\n debugLogging: false\n }\n });\n\n const targetGroup = app.addResource(aws.rds.ProxyDefaultTargetGroup, {\n name: `${prefix}pg-proxy`,\n config: {\n dbProxyName: proxy.output.name,\n connectionPoolConfig: {\n maxConnectionsPercent: 70,\n maxIdleConnectionsPercent: 50,\n connectionBorrowTimeout: 10\n }\n }\n });\n\n app.addResource(aws.rds.ProxyTarget, {\n name: `${prefix}pg-proxy`,\n config: {\n dbProxyName: proxy.output.name,\n targetGroupName: targetGroup.output.name,\n dbClusterIdentifier: cluster.output.id\n },\n // The proxy can only register a cluster whose instances are available.\n opts: { dependsOn: instances.map(instance => instance.output) }\n });\n\n return { role, proxy, targetGroup };\n}\n"],"names":["POSTGRES_DATABASE","POSTGRES_USER","POSTGRES_PORT","ENGINE","ENGINE_MAJOR_VERSION","PARAMETER_GROUP_FAMILY","getLatestEngineVersion","pulumi","aws","assumeRolePolicy","service","JSON","CorePostgres","createAppModule","app","params","network","protect","getEngineVersion","prefix","name","value","database","Database","password","random","secret","subnetGroup","parameterGroup","finalSnapshotSuffix","cluster","undefined","instances","index","isWriter","proxy","addProxy","role","arn","targetGroup","instance"],"mappings":";;;;AAYO,MAAMA,oBAAoB;AAC1B,MAAMC,gBAAgB;AACtB,MAAMC,gBAAgB;AAG7B,MAAMC,SAAS;AACf,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;AAiC/B,MAAMC,yBAAyB,IACpBC,0CAAAA,MAAa,CAChBC,uCAAAA,GAAAA,CAAAA,gBAAwB,CAAC;QAAE,QAAQL;QAAQ,SAASC;QAAsB,QAAQ;IAAK,IACzF,aAAa;AAGnB,MAAMK,mBAAmB,CAACC,UACtBC,KAAK,SAAS,CAAC;QACX,SAAS;QACT,WAAW;YAAC;gBAAE,QAAQ;gBAAS,WAAW;oBAAE,SAASD;gBAAQ;gBAAG,QAAQ;YAAiB;SAAE;IAC/F;AAcG,MAAME,eAAeC,gBAAgB;IACxC,MAAM;IACN,QAAOC,GAAc,EAAEC,MAA0B;QAC7C,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;QAC7B,MAAMG,mBAAmBH,OAAO,gBAAgB,IAAIT;QACpD,MAAMa,SAASJ,OAAO,UAAU,IAAI;QACpC,MAAMK,OAAO,CAACC,QAAkB,GAAGF,SAASE,OAAO;QACnD,MAAMC,WAAWP,OAAO,WAAW,IAAI;QACvC,MAAMQ,WAAWD,SAAS,MAAM,CAAC,GAAG,WAAW,KAAKA,SAAS,KAAK,CAAC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pConfig } from "./getIdpConfig.js";
|
|
2
|
+
import { getUserWritableAttributes } from "../CoreCognito.js";
|
|
2
3
|
import { getEnvVariableAwsRegion } from "../../../env/awsRegion.js";
|
|
3
4
|
import * as __rspack_external__pulumi_aws_9e2bee2d from "@pulumi/aws";
|
|
4
5
|
import * as __rspack_external__pulumi_pulumi_f3e773ed from "@pulumi/pulumi";
|
|
@@ -41,6 +42,16 @@ const configureAdminCognitoFederation = (app, config)=>{
|
|
|
41
42
|
return config.providerType;
|
|
42
43
|
})
|
|
43
44
|
]);
|
|
45
|
+
const mappedAttributes = idpConfigs.flatMap((config)=>{
|
|
46
|
+
const mapping = config.attributeMapping || {};
|
|
47
|
+
return Object.keys(mapping).filter((name)=>"username" !== name);
|
|
48
|
+
});
|
|
49
|
+
appClient.config.writeAttributes(getUserWritableAttributes(userPool.output.schemas).apply((attributes)=>[
|
|
50
|
+
...new Set([
|
|
51
|
+
...attributes,
|
|
52
|
+
...mappedAttributes
|
|
53
|
+
])
|
|
54
|
+
]));
|
|
44
55
|
appClient.config.allowedOauthScopes([
|
|
45
56
|
"profile",
|
|
46
57
|
"email",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/cognitoIdentityProviders/configure.js","sources":["../../../../../src/pulumi/apps/core/cognitoIdentityProviders/configure.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { type UserPoolDomainArgs } from \"@pulumi/aws/cognito/userPoolDomain.js\";\nimport { type IdentityProviderArgs } from \"@pulumi/aws/cognito/index.js\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport {\n type PulumiApp,\n type PulumiAppResource,\n type PulumiAppResourceConstructor\n} from \"@webiny/pulumi\";\nimport { getIdpConfig } from \"./getIdpConfig.js\";\nimport { getEnvVariableAwsRegion } from \"~/pulumi/env/awsRegion.js\";\n\nexport type IdentityAttributeMapping = {\n \"custom:id\": string;\n username: string;\n email: string;\n family_name: string;\n given_name: string;\n [key: string]: string;\n};\n\nexport interface CognitoIdentityProvidersConfig {\n domain:\n | string\n | {\n name: UserPoolDomainArgs[\"domain\"];\n certificateArn?: UserPoolDomainArgs[\"certificateArn\"];\n };\n identityProviders: CognitoIdentityProviderConfig[];\n callbackUrls: string[];\n logoutUrls?: string[];\n}\n\nexport interface CognitoIdentityProviderConfig {\n name?: string;\n type: \"google\" | \"facebook\" | \"amazon\" | \"apple\" | \"oidc\";\n providerDetails: IdentityProviderArgs[\"providerDetails\"];\n idpIdentifiers?: IdentityProviderArgs[\"idpIdentifiers\"];\n attributeMapping?: IdentityAttributeMapping;\n}\n\nconst isString = (value?: any): value is string => {\n return typeof value === \"string\";\n};\n\nexport const configureAdminCognitoFederation = (\n app: PulumiApp,\n config: CognitoIdentityProvidersConfig\n) => {\n const region = getEnvVariableAwsRegion();\n\n const userPool = app.resources.userPool as PulumiAppResource<\n PulumiAppResourceConstructor<aws.cognito.UserPool>\n >;\n\n const appClient = app.resources.userPoolClient as PulumiAppResource<\n PulumiAppResourceConstructor<aws.cognito.UserPoolClient>\n >;\n\n /**\n * We need to create a user pool domain, which is used to interact with the federated identity providers.\n */\n const userPoolDomain = app.addResource(aws.cognito.UserPoolDomain, {\n name: \"cognitoUserPoolDomain\",\n config: {\n domain: isString(config.domain) ? config.domain : config.domain.name,\n certificateArn: isString(config.domain) ? undefined : config.domain.certificateArn,\n userPoolId: userPool.output.id\n }\n });\n\n app.addOutput(\n \"cognitoUserPoolDomain\",\n pulumi.interpolate`${userPoolDomain.output.domain}.auth.${region}.amazoncognito.com`\n );\n\n const idpConfigs: aws.cognito.IdentityProviderArgs[] = [];\n const idpOutputs: pulumi.Output<aws.cognito.IdentityProvider>[] = [];\n\n for (const idp of config.identityProviders) {\n const config = getIdpConfig(idp.type, userPool.output.id, idp);\n\n // The idea to lowercase the provider name emerged while working on backwards compatibility issue.\n // Basically, in cases where a user used the OIDC provider and did not specify a name, instead of\n // using `OIDC` as the name, we wanted to ensure `oidc` is used. But, what I soon realized is that\n // by simply lowercasing the name, we can avoid the need to check for the provider type and name.\n // And although this will now happen for all providers, it's not a problem since Pulumi requires\n // names to be all lowercase anyway.\n const name = config.providerName.toString().toLowerCase();\n\n const idpResource = app.addResource(aws.cognito.IdentityProvider, { name, config });\n idpOutputs.push(idpResource.output);\n\n idpConfigs.push(config);\n }\n\n appClient.opts.dependsOn = [\n ...(appClient.opts.dependsOn\n ? Array.isArray(appClient.opts.dependsOn)\n ? appClient.opts.dependsOn\n : [appClient.opts.dependsOn]\n : []),\n ...idpOutputs\n ] as pulumi.Input<pulumi.Resource>[];\n\n appClient.config.supportedIdentityProviders([\n \"COGNITO\",\n ...idpConfigs.map(config => {\n // For built-in identity providers, we use the type as the name. Only for OIDC,\n // we allow the user to provide a custom name, and we only use the type as a fallback.\n if (config.providerType === \"OIDC\") {\n return config.providerName;\n }\n return config.providerType;\n })\n ]);\n\n appClient.config.allowedOauthScopes([\"profile\", \"email\", \"openid\"]);\n appClient.config.allowedOauthFlows([\"implicit\", \"code\"]);\n appClient.config.allowedOauthFlowsUserPoolClient(true);\n appClient.config.callbackUrls(config.callbackUrls);\n appClient.config.logoutUrls(config.logoutUrls ?? config.callbackUrls);\n};\n"],"names":["isString","value","configureAdminCognitoFederation","app","config","region","getEnvVariableAwsRegion","userPool","appClient","userPoolDomain","aws","undefined","pulumi","idpConfigs","idpOutputs","idp","getIdpConfig","name","idpResource","Array"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/cognitoIdentityProviders/configure.js","sources":["../../../../../src/pulumi/apps/core/cognitoIdentityProviders/configure.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport { type UserPoolDomainArgs } from \"@pulumi/aws/cognito/userPoolDomain.js\";\nimport { type IdentityProviderArgs } from \"@pulumi/aws/cognito/index.js\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport {\n type PulumiApp,\n type PulumiAppResource,\n type PulumiAppResourceConstructor\n} from \"@webiny/pulumi\";\nimport { getIdpConfig } from \"./getIdpConfig.js\";\nimport { getUserWritableAttributes } from \"../CoreCognito.js\";\nimport { getEnvVariableAwsRegion } from \"~/pulumi/env/awsRegion.js\";\n\nexport type IdentityAttributeMapping = {\n \"custom:id\": string;\n username: string;\n email: string;\n family_name: string;\n given_name: string;\n [key: string]: string;\n};\n\nexport interface CognitoIdentityProvidersConfig {\n domain:\n | string\n | {\n name: UserPoolDomainArgs[\"domain\"];\n certificateArn?: UserPoolDomainArgs[\"certificateArn\"];\n };\n identityProviders: CognitoIdentityProviderConfig[];\n callbackUrls: string[];\n logoutUrls?: string[];\n}\n\nexport interface CognitoIdentityProviderConfig {\n name?: string;\n type: \"google\" | \"facebook\" | \"amazon\" | \"apple\" | \"oidc\";\n providerDetails: IdentityProviderArgs[\"providerDetails\"];\n idpIdentifiers?: IdentityProviderArgs[\"idpIdentifiers\"];\n attributeMapping?: IdentityAttributeMapping;\n}\n\nconst isString = (value?: any): value is string => {\n return typeof value === \"string\";\n};\n\nexport const configureAdminCognitoFederation = (\n app: PulumiApp,\n config: CognitoIdentityProvidersConfig\n) => {\n const region = getEnvVariableAwsRegion();\n\n const userPool = app.resources.userPool as PulumiAppResource<\n PulumiAppResourceConstructor<aws.cognito.UserPool>\n >;\n\n const appClient = app.resources.userPoolClient as PulumiAppResource<\n PulumiAppResourceConstructor<aws.cognito.UserPoolClient>\n >;\n\n /**\n * We need to create a user pool domain, which is used to interact with the federated identity providers.\n */\n const userPoolDomain = app.addResource(aws.cognito.UserPoolDomain, {\n name: \"cognitoUserPoolDomain\",\n config: {\n domain: isString(config.domain) ? config.domain : config.domain.name,\n certificateArn: isString(config.domain) ? undefined : config.domain.certificateArn,\n userPoolId: userPool.output.id\n }\n });\n\n app.addOutput(\n \"cognitoUserPoolDomain\",\n pulumi.interpolate`${userPoolDomain.output.domain}.auth.${region}.amazoncognito.com`\n );\n\n const idpConfigs: aws.cognito.IdentityProviderArgs[] = [];\n const idpOutputs: pulumi.Output<aws.cognito.IdentityProvider>[] = [];\n\n for (const idp of config.identityProviders) {\n const config = getIdpConfig(idp.type, userPool.output.id, idp);\n\n // The idea to lowercase the provider name emerged while working on backwards compatibility issue.\n // Basically, in cases where a user used the OIDC provider and did not specify a name, instead of\n // using `OIDC` as the name, we wanted to ensure `oidc` is used. But, what I soon realized is that\n // by simply lowercasing the name, we can avoid the need to check for the provider type and name.\n // And although this will now happen for all providers, it's not a problem since Pulumi requires\n // names to be all lowercase anyway.\n const name = config.providerName.toString().toLowerCase();\n\n const idpResource = app.addResource(aws.cognito.IdentityProvider, { name, config });\n idpOutputs.push(idpResource.output);\n\n idpConfigs.push(config);\n }\n\n appClient.opts.dependsOn = [\n ...(appClient.opts.dependsOn\n ? Array.isArray(appClient.opts.dependsOn)\n ? appClient.opts.dependsOn\n : [appClient.opts.dependsOn]\n : []),\n ...idpOutputs\n ] as pulumi.Input<pulumi.Resource>[];\n\n appClient.config.supportedIdentityProviders([\n \"COGNITO\",\n ...idpConfigs.map(config => {\n // For built-in identity providers, we use the type as the name. Only for OIDC,\n // we allow the user to provide a custom name, and we only use the type as a fallback.\n if (config.providerType === \"OIDC\") {\n return config.providerName;\n }\n return config.providerType;\n })\n ]);\n\n /* Cognito writes the mapped attributes on every federated sign-in, so the app client must be\n allowed to write them. Note: this includes `custom:id`, which then also becomes writable by\n users through their own access token. */\n const mappedAttributes = idpConfigs.flatMap(config => {\n const mapping = (config.attributeMapping || {}) as Record<string, unknown>;\n return Object.keys(mapping).filter(name => name !== \"username\");\n });\n appClient.config.writeAttributes(\n getUserWritableAttributes(userPool.output.schemas).apply(attributes => {\n return [...new Set([...attributes, ...mappedAttributes])];\n })\n );\n\n appClient.config.allowedOauthScopes([\"profile\", \"email\", \"openid\"]);\n appClient.config.allowedOauthFlows([\"implicit\", \"code\"]);\n appClient.config.allowedOauthFlowsUserPoolClient(true);\n appClient.config.callbackUrls(config.callbackUrls);\n appClient.config.logoutUrls(config.logoutUrls ?? config.callbackUrls);\n};\n"],"names":["isString","value","configureAdminCognitoFederation","app","config","region","getEnvVariableAwsRegion","userPool","appClient","userPoolDomain","aws","undefined","pulumi","idpConfigs","idpOutputs","idp","getIdpConfig","name","idpResource","Array","mappedAttributes","mapping","Object","getUserWritableAttributes","attributes","Set"],"mappings":";;;;;AA0CA,MAAMA,WAAW,CAACC,QACP,AAAiB,YAAjB,OAAOA;AAGX,MAAMC,kCAAkC,CAC3CC,KACAC;IAEA,MAAMC,SAASC;IAEf,MAAMC,WAAWJ,IAAI,SAAS,CAAC,QAAQ;IAIvC,MAAMK,YAAYL,IAAI,SAAS,CAAC,cAAc;IAO9C,MAAMM,iBAAiBN,IAAI,WAAW,CAACO,uCAAAA,OAAAA,CAAAA,cAA0B,EAAE;QAC/D,MAAM;QACN,QAAQ;YACJ,QAAQV,SAASI,OAAO,MAAM,IAAIA,OAAO,MAAM,GAAGA,OAAO,MAAM,CAAC,IAAI;YACpE,gBAAgBJ,SAASI,OAAO,MAAM,IAAIO,SAAYP,OAAO,MAAM,CAAC,cAAc;YAClF,YAAYG,SAAS,MAAM,CAAC,EAAE;QAClC;IACJ;IAEAJ,IAAI,SAAS,CACT,yBACAS,0CAAAA,WAAkB,CAAC,EAAEH,eAAe,MAAM,CAAC,MAAM,CAAC,MAAM,EAAEJ,OAAO,kBAAkB,CAAC;IAGxF,MAAMQ,aAAiD,EAAE;IACzD,MAAMC,aAA4D,EAAE;IAEpE,KAAK,MAAMC,OAAOX,OAAO,iBAAiB,CAAE;QACxC,MAAMA,SAASY,aAAaD,IAAI,IAAI,EAAER,SAAS,MAAM,CAAC,EAAE,EAAEQ;QAQ1D,MAAME,OAAOb,OAAO,YAAY,CAAC,QAAQ,GAAG,WAAW;QAEvD,MAAMc,cAAcf,IAAI,WAAW,CAACO,uCAAAA,OAAAA,CAAAA,gBAA4B,EAAE;YAAEO;YAAMb;QAAO;QACjFU,WAAW,IAAI,CAACI,YAAY,MAAM;QAElCL,WAAW,IAAI,CAACT;IACpB;IAEAI,UAAU,IAAI,CAAC,SAAS,GAAG;WACnBA,UAAU,IAAI,CAAC,SAAS,GACtBW,MAAM,OAAO,CAACX,UAAU,IAAI,CAAC,SAAS,IAClCA,UAAU,IAAI,CAAC,SAAS,GACxB;YAACA,UAAU,IAAI,CAAC,SAAS;SAAC,GAC9B,EAAE;WACLM;KACN;IAEDN,UAAU,MAAM,CAAC,0BAA0B,CAAC;QACxC;WACGK,WAAW,GAAG,CAACT,CAAAA;YAGd,IAAIA,AAAwB,WAAxBA,OAAO,YAAY,EACnB,OAAOA,OAAO,YAAY;YAE9B,OAAOA,OAAO,YAAY;QAC9B;KACH;IAKD,MAAMgB,mBAAmBP,WAAW,OAAO,CAACT,CAAAA;QACxC,MAAMiB,UAAWjB,OAAO,gBAAgB,IAAI,CAAC;QAC7C,OAAOkB,OAAO,IAAI,CAACD,SAAS,MAAM,CAACJ,CAAAA,OAAQA,AAAS,eAATA;IAC/C;IACAT,UAAU,MAAM,CAAC,eAAe,CAC5Be,0BAA0BhB,SAAS,MAAM,CAAC,OAAO,EAAE,KAAK,CAACiB,CAAAA,aAC9C;eAAI,IAAIC,IAAI;mBAAID;mBAAeJ;aAAiB;SAAE;IAIjEZ,UAAU,MAAM,CAAC,kBAAkB,CAAC;QAAC;QAAW;QAAS;KAAS;IAClEA,UAAU,MAAM,CAAC,iBAAiB,CAAC;QAAC;QAAY;KAAO;IACvDA,UAAU,MAAM,CAAC,+BAA+B,CAAC;IACjDA,UAAU,MAAM,CAAC,YAAY,CAACJ,OAAO,YAAY;IACjDI,UAAU,MAAM,CAAC,UAAU,CAACJ,OAAO,UAAU,IAAIA,OAAO,YAAY;AACxE"}
|
|
@@ -13,7 +13,7 @@ export interface CoreDynamoDbTables {
|
|
|
13
13
|
/**
|
|
14
14
|
* The core's DynamoDB tables (the primary one and the audit logs one) and their stack outputs.
|
|
15
15
|
*
|
|
16
|
-
* With `<Infra.
|
|
17
|
-
* included, in the database, so `<Infra.DynamoDb.Pitr />` has nothing to apply to either.
|
|
16
|
+
* With `<Infra.AuroraPostgres />` there are none: the API keeps all of its data, the service
|
|
17
|
+
* manifests included, in the database, so `<Infra.DynamoDb.Pitr />` has nothing to apply to either.
|
|
18
18
|
*/
|
|
19
19
|
export declare const addCoreDynamoDb: (app: PulumiApp, params: CoreDynamoDbParams) => CoreDynamoDbTables;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/coreDynamoDb.js","sources":["../../../../src/pulumi/apps/core/coreDynamoDb.ts"],"sourcesContent":["import type { PulumiApp } from \"@webiny/pulumi\";\nimport { CoreDynamo } from \"./CoreDynamo.js\";\nimport { CoreAuditLogsDynamo } from \"./CoreAuditLogsDynamo.js\";\n\nexport interface CoreDynamoDbParams {\n /* The project has `<Infra.
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/coreDynamoDb.js","sources":["../../../../src/pulumi/apps/core/coreDynamoDb.ts"],"sourcesContent":["import type { PulumiApp } from \"@webiny/pulumi\";\nimport { CoreDynamo } from \"./CoreDynamo.js\";\nimport { CoreAuditLogsDynamo } from \"./CoreAuditLogsDynamo.js\";\n\nexport interface CoreDynamoDbParams {\n /* The project has `<Infra.AuroraPostgres />`. */\n usesPostgres: boolean;\n protect: boolean;\n pointInTimeRecovery: boolean;\n}\n\nexport interface CoreDynamoDbTables {\n /* Not created with `<Infra.AuroraPostgres />`. */\n dynamoDbTable: CoreDynamo | undefined;\n /* Not created with `<Infra.AuroraPostgres />`. */\n auditLogsDynamoDbTable: CoreAuditLogsDynamo | undefined;\n}\n\n/**\n * The core's DynamoDB tables (the primary one and the audit logs one) and their stack outputs.\n *\n * With `<Infra.AuroraPostgres />` there are none: the API keeps all of its data, the service\n * manifests included, in the database, so `<Infra.DynamoDb.Pitr />` has nothing to apply to either.\n */\nexport const addCoreDynamoDb = (app: PulumiApp, params: CoreDynamoDbParams): CoreDynamoDbTables => {\n if (params.usesPostgres) {\n return { dynamoDbTable: undefined, auditLogsDynamoDbTable: undefined };\n }\n\n const { protect, pointInTimeRecovery } = params;\n const dynamoDbTable = app.addModule(CoreDynamo, { protect, pointInTimeRecovery });\n const auditLogsDynamoDbTable = app.addModule(CoreAuditLogsDynamo, {\n protect,\n pointInTimeRecovery\n });\n\n app.addOutputs({\n primaryDynamodbTableArn: dynamoDbTable.output.arn,\n primaryDynamodbTableName: dynamoDbTable.output.name,\n primaryDynamodbTableHashKey: dynamoDbTable.output.hashKey,\n primaryDynamodbTableRangeKey: dynamoDbTable.output.rangeKey,\n auditLogsDynamodbTableArn: auditLogsDynamoDbTable.output.arn,\n auditLogsDynamodbTableName: auditLogsDynamoDbTable.output.name,\n auditLogsDynamodbTableHashKey: auditLogsDynamoDbTable.output.hashKey,\n auditLogsDynamodbTableRangeKey: auditLogsDynamoDbTable.output.rangeKey\n });\n\n return { dynamoDbTable, auditLogsDynamoDbTable };\n};\n"],"names":["addCoreDynamoDb","app","params","undefined","protect","pointInTimeRecovery","dynamoDbTable","CoreDynamo","auditLogsDynamoDbTable","CoreAuditLogsDynamo"],"mappings":";;AAwBO,MAAMA,kBAAkB,CAACC,KAAgBC;IAC5C,IAAIA,OAAO,YAAY,EACnB,OAAO;QAAE,eAAeC;QAAW,wBAAwBA;IAAU;IAGzE,MAAM,EAAEC,OAAO,EAAEC,mBAAmB,EAAE,GAAGH;IACzC,MAAMI,gBAAgBL,IAAI,SAAS,CAACM,YAAY;QAAEH;QAASC;IAAoB;IAC/E,MAAMG,yBAAyBP,IAAI,SAAS,CAACQ,qBAAqB;QAC9DL;QACAC;IACJ;IAEAJ,IAAI,UAAU,CAAC;QACX,yBAAyBK,cAAc,MAAM,CAAC,GAAG;QACjD,0BAA0BA,cAAc,MAAM,CAAC,IAAI;QACnD,6BAA6BA,cAAc,MAAM,CAAC,OAAO;QACzD,8BAA8BA,cAAc,MAAM,CAAC,QAAQ;QAC3D,2BAA2BE,uBAAuB,MAAM,CAAC,GAAG;QAC5D,4BAA4BA,uBAAuB,MAAM,CAAC,IAAI;QAC9D,+BAA+BA,uBAAuB,MAAM,CAAC,OAAO;QACpE,gCAAgCA,uBAAuB,MAAM,CAAC,QAAQ;IAC1E;IAEA,OAAO;QAAEF;QAAeE;IAAuB;AACnD"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as pulumi from "@pulumi/pulumi";
|
|
2
2
|
import type { PulumiApp } from "@webiny/pulumi";
|
|
3
3
|
import type { ServiceManifest } from "../../../pulumi/utils/addServiceManifestTableItem.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The core stack output that carries the core's service manifests, with `<Infra.AuroraPostgres />`.
|
|
6
|
+
*/
|
|
5
7
|
export declare const CORE_SERVICE_MANIFESTS_OUTPUT = "serviceManifests";
|
|
6
8
|
export interface CoreServiceManifestParams {
|
|
7
9
|
eventBus: {
|
|
@@ -22,8 +24,8 @@ export interface CoreServiceManifestParams {
|
|
|
22
24
|
/** The `core` service manifest: the event bus, and the primary DynamoDB table when there is one. */
|
|
23
25
|
export declare const createCoreServiceManifest: (params: CoreServiceManifestParams) => ServiceManifest;
|
|
24
26
|
/**
|
|
25
|
-
* With `<Infra.
|
|
26
|
-
* before the api's schema-setup function exists, and the database is in private subnets the
|
|
27
|
-
* can't reach, so the api deploy passes them on to the schema setup, which stores them.
|
|
27
|
+
* With `<Infra.AuroraPostgres />`: puts the core's service manifests in its stack output. The core
|
|
28
|
+
* deploys before the api's schema-setup function exists, and the database is in private subnets the
|
|
29
|
+
* deploy can't reach, so the api deploy passes them on to the schema setup, which stores them.
|
|
28
30
|
*/
|
|
29
31
|
export declare const addServiceManifestsOutput: (app: PulumiApp, manifests: ServiceManifest[]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/coreServiceManifests.js","sources":["../../../../src/pulumi/apps/core/coreServiceManifests.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { ServiceManifest } from \"~/pulumi/utils/addServiceManifestTableItem.js\";\n\n
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/coreServiceManifests.js","sources":["../../../../src/pulumi/apps/core/coreServiceManifests.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { ServiceManifest } from \"~/pulumi/utils/addServiceManifestTableItem.js\";\n\n/**\n * The core stack output that carries the core's service manifests, with `<Infra.AuroraPostgres />`.\n */\nexport const CORE_SERVICE_MANIFESTS_OUTPUT = \"serviceManifests\";\n\nexport interface CoreServiceManifestParams {\n eventBus: {\n output: { arn: pulumi.Output<string>; name: pulumi.Output<string> };\n };\n /* The primary DynamoDB table. Not in the manifest with `<Infra.AuroraPostgres />`. */\n dynamoDbTable?: {\n output: {\n arn: pulumi.Output<string>;\n name: pulumi.Output<string>;\n hashKey: pulumi.Output<string>;\n rangeKey: pulumi.Output<string | undefined>;\n };\n };\n}\n\n/** The `core` service manifest: the event bus, and the primary DynamoDB table when there is one. */\nexport const createCoreServiceManifest = (params: CoreServiceManifestParams): ServiceManifest => {\n const { eventBus, dynamoDbTable } = params;\n return {\n name: \"core\",\n manifest: {\n eventBus: {\n arn: eventBus.output.arn,\n name: eventBus.output.name\n },\n ...(dynamoDbTable && {\n dynamodbTable: {\n arn: dynamoDbTable.output.arn,\n name: dynamoDbTable.output.name,\n hashKey: dynamoDbTable.output.hashKey,\n rangeKey: dynamoDbTable.output.rangeKey\n }\n })\n }\n };\n};\n\n/**\n * With `<Infra.AuroraPostgres />`: puts the core's service manifests in its stack output. The core\n * deploys before the api's schema-setup function exists, and the database is in private subnets the\n * deploy can't reach, so the api deploy passes them on to the schema setup, which stores them.\n */\nexport const addServiceManifestsOutput = (app: PulumiApp, manifests: ServiceManifest[]) => {\n app.addOutput(\n CORE_SERVICE_MANIFESTS_OUTPUT,\n pulumi.output(manifests.map(({ name, manifest }) => ({ name, manifest })))\n );\n};\n"],"names":["CORE_SERVICE_MANIFESTS_OUTPUT","createCoreServiceManifest","params","eventBus","dynamoDbTable","addServiceManifestsOutput","app","manifests","pulumi","name","manifest"],"mappings":";AAOO,MAAMA,gCAAgC;AAkBtC,MAAMC,4BAA4B,CAACC;IACtC,MAAM,EAAEC,QAAQ,EAAEC,aAAa,EAAE,GAAGF;IACpC,OAAO;QACH,MAAM;QACN,UAAU;YACN,UAAU;gBACN,KAAKC,SAAS,MAAM,CAAC,GAAG;gBACxB,MAAMA,SAAS,MAAM,CAAC,IAAI;YAC9B;YACA,GAAIC,iBAAiB;gBACjB,eAAe;oBACX,KAAKA,cAAc,MAAM,CAAC,GAAG;oBAC7B,MAAMA,cAAc,MAAM,CAAC,IAAI;oBAC/B,SAASA,cAAc,MAAM,CAAC,OAAO;oBACrC,UAAUA,cAAc,MAAM,CAAC,QAAQ;gBAC3C;YACJ,CAAC;QACL;IACJ;AACJ;AAOO,MAAMC,4BAA4B,CAACC,KAAgBC;IACtDD,IAAI,SAAS,CACTN,+BACAQ,0CAAAA,MAAa,CAACD,UAAU,GAAG,CAAC,CAAC,EAAEE,IAAI,EAAEC,QAAQ,EAAE,GAAM;YAAED;YAAMC;QAAS;AAE9E"}
|
|
@@ -8,7 +8,14 @@ export interface CoreVpcEndpointsParams {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* The VPC endpoints of `<Infra.Vpc useVpcEndpoints />`: gateways for S3 and DynamoDB, interfaces for
|
|
11
|
-
* SQS and EventBridge. With `<Infra.
|
|
12
|
-
* talks to DynamoDB.
|
|
11
|
+
* SQS and EventBridge. With `<Infra.AuroraPostgres />` there's no DynamoDB endpoint: nothing in the
|
|
12
|
+
* VPC talks to DynamoDB.
|
|
13
13
|
*/
|
|
14
14
|
export declare const addCoreVpcEndpoints: (app: PulumiApp, params: CoreVpcEndpointsParams) => void;
|
|
15
|
+
/**
|
|
16
|
+
* The DynamoDB gateway endpoint: DynamoDB traffic from the private subnets goes to it instead of
|
|
17
|
+
* through the NAT gateway. Gateway endpoints cost nothing. Added by `<Infra.Vpc useVpcEndpoints />`,
|
|
18
|
+
* and on a DynamoDB default storage with a `<Infra.TenantStorage.AuroraPostgres>`, whose API functions
|
|
19
|
+
* run in the VPC.
|
|
20
|
+
*/
|
|
21
|
+
export declare const addDynamoDbGatewayEndpoint: (app: PulumiApp, params: Pick<CoreVpcEndpointsParams, "vpc" | "region">) => import("@webiny/pulumi").PulumiAppResource<typeof import("@pulumi/aws/ec2/vpcEndpoint.js").VpcEndpoint>;
|
|
@@ -13,16 +13,7 @@ const addCoreVpcEndpoints = (app, params)=>{
|
|
|
13
13
|
]
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
if (!params.usesPostgres) app
|
|
17
|
-
name: "vpc-dynamodb-vpc-endpoint",
|
|
18
|
-
config: {
|
|
19
|
-
vpcId: vpc.output.id,
|
|
20
|
-
serviceName: __rspack_external__pulumi_pulumi_f3e773ed.interpolate`com.amazonaws.${region}.dynamodb`,
|
|
21
|
-
routeTableIds: [
|
|
22
|
-
routeTables.privateSubnets.output.id
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
});
|
|
16
|
+
if (!params.usesPostgres) addDynamoDbGatewayEndpoint(app, params);
|
|
26
17
|
app.addResource(__rspack_external__pulumi_aws_9e2bee2d.ec2.VpcEndpoint, {
|
|
27
18
|
name: "vpc-sqs-vpc-endpoint",
|
|
28
19
|
config: {
|
|
@@ -50,6 +41,19 @@ const addCoreVpcEndpoints = (app, params)=>{
|
|
|
50
41
|
}
|
|
51
42
|
});
|
|
52
43
|
};
|
|
53
|
-
|
|
44
|
+
const addDynamoDbGatewayEndpoint = (app, params)=>{
|
|
45
|
+
const { vpc, routeTables } = params.vpc;
|
|
46
|
+
return app.addResource(__rspack_external__pulumi_aws_9e2bee2d.ec2.VpcEndpoint, {
|
|
47
|
+
name: "vpc-dynamodb-vpc-endpoint",
|
|
48
|
+
config: {
|
|
49
|
+
vpcId: vpc.output.id,
|
|
50
|
+
serviceName: __rspack_external__pulumi_pulumi_f3e773ed.interpolate`com.amazonaws.${params.region}.dynamodb`,
|
|
51
|
+
routeTableIds: [
|
|
52
|
+
routeTables.privateSubnets.output.id
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
export { addCoreVpcEndpoints, addDynamoDbGatewayEndpoint };
|
|
54
58
|
|
|
55
59
|
//# sourceMappingURL=coreVpcEndpoints.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pulumi/apps/core/coreVpcEndpoints.js","sources":["../../../../src/pulumi/apps/core/coreVpcEndpoints.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { CoreVpc } from \"./CoreVpc.js\";\n\nexport interface CoreVpcEndpointsParams {\n vpc: Pick<CoreVpc, \"vpc\" | \"subnets\" | \"routeTables\">;\n region: pulumi.Input<string>;\n /* The project has `<Infra.
|
|
1
|
+
{"version":3,"file":"pulumi/apps/core/coreVpcEndpoints.js","sources":["../../../../src/pulumi/apps/core/coreVpcEndpoints.ts"],"sourcesContent":["import * as aws from \"@pulumi/aws\";\nimport * as pulumi from \"@pulumi/pulumi\";\nimport type { PulumiApp } from \"@webiny/pulumi\";\nimport type { CoreVpc } from \"./CoreVpc.js\";\n\nexport interface CoreVpcEndpointsParams {\n vpc: Pick<CoreVpc, \"vpc\" | \"subnets\" | \"routeTables\">;\n region: pulumi.Input<string>;\n /* The project has `<Infra.AuroraPostgres />`. */\n usesPostgres: boolean;\n}\n\n/**\n * The VPC endpoints of `<Infra.Vpc useVpcEndpoints />`: gateways for S3 and DynamoDB, interfaces for\n * SQS and EventBridge. With `<Infra.AuroraPostgres />` there's no DynamoDB endpoint: nothing in the\n * VPC talks to DynamoDB.\n */\nexport const addCoreVpcEndpoints = (app: PulumiApp, params: CoreVpcEndpointsParams) => {\n const { vpc, subnets, routeTables } = params.vpc;\n const { region } = params;\n\n app.addResource(aws.ec2.VpcEndpoint, {\n name: \"vpc-s3-vpc-endpoint\",\n config: {\n vpcId: vpc.output.id,\n serviceName: pulumi.interpolate`com.amazonaws.${region}.s3`,\n routeTableIds: [routeTables.privateSubnets.output.id]\n }\n });\n\n if (!params.usesPostgres) {\n addDynamoDbGatewayEndpoint(app, params);\n }\n\n app.addResource(aws.ec2.VpcEndpoint, {\n name: \"vpc-sqs-vpc-endpoint\",\n config: {\n vpcId: vpc.output.id,\n serviceName: pulumi.interpolate`com.amazonaws.${region}.sqs`,\n vpcEndpointType: \"Interface\",\n privateDnsEnabled: true,\n securityGroupIds: [vpc.output.defaultSecurityGroupId],\n subnetIds: subnets.private.map(subNet => subNet.output.id)\n }\n });\n\n app.addResource(aws.ec2.VpcEndpoint, {\n name: \"vpc-events-vpc-endpoint\",\n config: {\n vpcId: vpc.output.id,\n serviceName: pulumi.interpolate`com.amazonaws.${region}.events`,\n vpcEndpointType: \"Interface\",\n privateDnsEnabled: true,\n securityGroupIds: [vpc.output.defaultSecurityGroupId],\n subnetIds: subnets.private.map(subNet => subNet.output.id)\n }\n });\n};\n\n/**\n * The DynamoDB gateway endpoint: DynamoDB traffic from the private subnets goes to it instead of\n * through the NAT gateway. Gateway endpoints cost nothing. Added by `<Infra.Vpc useVpcEndpoints />`,\n * and on a DynamoDB default storage with a `<Infra.TenantStorage.AuroraPostgres>`, whose API functions\n * run in the VPC.\n */\nexport const addDynamoDbGatewayEndpoint = (\n app: PulumiApp,\n params: Pick<CoreVpcEndpointsParams, \"vpc\" | \"region\">\n) => {\n const { vpc, routeTables } = params.vpc;\n return app.addResource(aws.ec2.VpcEndpoint, {\n name: \"vpc-dynamodb-vpc-endpoint\",\n config: {\n vpcId: vpc.output.id,\n serviceName: pulumi.interpolate`com.amazonaws.${params.region}.dynamodb`,\n routeTableIds: [routeTables.privateSubnets.output.id]\n }\n });\n};\n"],"names":["addCoreVpcEndpoints","app","params","vpc","subnets","routeTables","region","aws","pulumi","addDynamoDbGatewayEndpoint","subNet"],"mappings":";;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MD,6BAA6B,CACtCR,KACAC;IAEA,MAAM,EAAEC,GAAG,EAAEE,WAAW,EAAE,GAAGH,OAAO,GAAG;IACvC,OAAOD,IAAI,WAAW,CAACM,uCAAAA,GAAAA,CAAAA,WAAmB,EAAE;QACxC,MAAM;QACN,QAAQ;YACJ,OAAOJ,IAAI,MAAM,CAAC,EAAE;YACpB,aAAaK,0CAAAA,WAAkB,CAAC,cAAc,EAAEN,OAAO,MAAM,CAAC,SAAS,CAAC;YACxE,eAAe;gBAACG,YAAY,cAAc,CAAC,MAAM,CAAC,EAAE;aAAC;QACzD;IACJ;AACJ"}
|
|
@@ -21,7 +21,8 @@ import { S3BucketVersioning } from "@webiny/project-extensions-aws/extensions/S3
|
|
|
21
21
|
import { applyAwsResourceTags, getAwsRegion } from "../awsUtils.js";
|
|
22
22
|
import { configureS3BucketMalwareProtection } from "./configureS3BucketMalwareProtection.js";
|
|
23
23
|
import { addCoreDynamoDb } from "./coreDynamoDb.js";
|
|
24
|
-
import { addCoreVpcEndpoints } from "./coreVpcEndpoints.js";
|
|
24
|
+
import { addCoreVpcEndpoints, addDynamoDbGatewayEndpoint } from "./coreVpcEndpoints.js";
|
|
25
|
+
import { getTenantStoragesFromExtension } from "../extensions/getTenantStoragesFromExtension.js";
|
|
25
26
|
import { getPostgresConfigFromExtension } from "../extensions/getPostgresConfigFromExtension.js";
|
|
26
27
|
import * as __rspack_external__pulumi_aws_9e2bee2d from "@pulumi/aws";
|
|
27
28
|
import * as __rspack_external__pulumi_random_073a0f72 from "@pulumi/random";
|
|
@@ -121,6 +122,12 @@ function createCorePulumiApp() {
|
|
|
121
122
|
pointInTimeRecovery
|
|
122
123
|
});
|
|
123
124
|
const vpc = isVpcEnabled(vpcExtensionsConfig, isProduction) ? app.addModule(CoreVpc) : null;
|
|
125
|
+
const usesVpcEndpoints = "object" == typeof vpcExtensionsConfig && Boolean(vpcExtensionsConfig.useVpcEndpoints);
|
|
126
|
+
const hasTenantStorages = getTenantStoragesFromExtension(projectConfig).length > 0;
|
|
127
|
+
if (vpc && hasTenantStorages && !usesPostgres && !usesVpcEndpoints) addDynamoDbGatewayEndpoint(app, {
|
|
128
|
+
vpc,
|
|
129
|
+
region: getAwsRegion(app)
|
|
130
|
+
});
|
|
124
131
|
const cognito = app.addModule(CoreCognito, {
|
|
125
132
|
protect,
|
|
126
133
|
useEmailAsUsername: false,
|