@friggframework/devtools 2.0.0--canary.658.e11f3b0.0 → 2.0.0--canary.737.83b4e17.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/frigg-cli/README.md +115 -31
- package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +33 -24
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
- package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
- package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
- package/frigg-cli/build-command/index.js +6 -0
- package/frigg-cli/deploy-command/index.js +6 -0
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +22 -5
- package/frigg-cli/init-command/backend-first-handler.js +395 -551
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/start-command/index.js +4 -0
- package/frigg-cli/start-command/start-command.test.js +3 -0
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
- package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
- package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +443 -0
- package/frigg-cli/validate-command/__tests__/validate-command.test.js +262 -0
- package/frigg-cli/validate-command/checks/config.js +504 -0
- package/frigg-cli/validate-command/checks/integrations.js +274 -0
- package/frigg-cli/validate-command/format-report.js +58 -0
- package/frigg-cli/validate-command/index.js +107 -0
- package/frigg-cli/validate-command/load-app-definition.js +105 -0
- package/frigg-cli/validate-command/schema-issues.js +154 -0
- package/frigg-cli/validate-command/validate-app-definition.js +60 -0
- package/infrastructure/README.md +32 -5
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +39 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +284 -0
- package/infrastructure/__tests__/postgres-config.test.js +245 -836
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +151 -0
- package/infrastructure/__tests__/scoped-environment.test.js +3 -0
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
- package/infrastructure/__tests__/template-generation.test.js +39 -8
- package/infrastructure/app-definition-schema-contract.test.js +634 -0
- package/infrastructure/create-frigg-infrastructure.js +4 -1
- package/infrastructure/create-frigg-infrastructure.test.js +51 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +80 -98
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +8 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +52 -6
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/database/migration-builder.js +21 -2
- package/infrastructure/domains/database/migration-builder.test.js +61 -6
- package/infrastructure/domains/database/migration-engines.js +93 -0
- package/infrastructure/domains/database/migration-engines.test.js +142 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
- package/infrastructure/domains/integration/integration-builder.js +2 -0
- package/infrastructure/domains/integration/integration-builder.test.js +22 -6
- package/infrastructure/domains/networking/vpc-builder.js +18 -8
- package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
- package/infrastructure/domains/shared/environment-builder.js +31 -5
- package/infrastructure/domains/shared/environment-builder.test.js +93 -7
- package/infrastructure/domains/shared/lambda-architectures.js +113 -0
- package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +39 -3
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +85 -5
- package/infrastructure/domains/shared/utilities/nested-node-modules.js +6 -5
- package/infrastructure/domains/shared/utilities/nested-node-modules.test.js +20 -26
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -12
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
- package/infrastructure/infrastructure-composer.js +12 -1
- package/infrastructure/infrastructure-composer.test.js +339 -794
- package/infrastructure/scripts/build-prisma-layer.js +136 -50
- package/infrastructure/scripts/build-prisma-layer.test.js +128 -7
- package/infrastructure/scripts/build-time-discovery.test.js +18 -3
- package/package.json +12 -10
- package/frigg-cli/index.test.js +0 -158
- package/infrastructure/integration.test.js +0 -381
|
@@ -1,914 +1,323 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PostgreSQL (Aurora) configuration through the full composer.
|
|
3
|
+
*
|
|
4
|
+
* AuroraBuilder has its own unit tests (domains/database/aurora-builder.test.js);
|
|
5
|
+
* these check that `database.postgres` in an app definition comes out of
|
|
6
|
+
* composeServerlessDefinition — the path `frigg deploy` takes — as the right
|
|
7
|
+
* CloudFormation resources, provider environment and IAM statements.
|
|
8
|
+
*
|
|
9
|
+
* AWS discovery is stubbed (no credentials or network needed) and the Prisma
|
|
10
|
+
* layer build is stubbed so the test never runs `npm install` into
|
|
11
|
+
* packages/devtools/layers/prisma.
|
|
3
12
|
*/
|
|
4
13
|
|
|
14
|
+
jest.mock('../domains/shared/resource-discovery', () => ({
|
|
15
|
+
...jest.requireActual('../domains/shared/resource-discovery'),
|
|
16
|
+
gatherDiscoveredResources: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
19
|
+
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
gatherDiscoveredResources,
|
|
24
|
+
} = require('../domains/shared/resource-discovery');
|
|
5
25
|
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
6
|
-
const { AWSDiscovery } = require('../aws-discovery');
|
|
7
|
-
const { mockClient } = require('aws-sdk-client-mock');
|
|
8
|
-
const { RDSClient, DescribeDBClustersCommand, DescribeDBSubnetGroupsCommand } = require('@aws-sdk/client-rds');
|
|
9
|
-
const { SecretsManagerClient, ListSecretsCommand, DescribeSecretCommand } = require('@aws-sdk/client-secrets-manager');
|
|
10
|
-
const { EC2Client, DescribeVpcsCommand, DescribeSubnetsCommand, DescribeSecurityGroupsCommand, DescribeRouteTablesCommand } = require('@aws-sdk/client-ec2');
|
|
11
|
-
const { KMSClient, ListAliasesCommand } = require('@aws-sdk/client-kms');
|
|
12
|
-
const { STSClient, GetCallerIdentityCommand } = require('@aws-sdk/client-sts');
|
|
13
|
-
|
|
14
|
-
// Create mocks for AWS SDK clients
|
|
15
|
-
const rdsMock = mockClient(RDSClient);
|
|
16
|
-
const secretsManagerMock = mockClient(SecretsManagerClient);
|
|
17
|
-
const ec2Mock = mockClient(EC2Client);
|
|
18
|
-
const kmsMock = mockClient(KMSClient);
|
|
19
|
-
const stsMock = mockClient(STSClient);
|
|
20
|
-
|
|
21
|
-
describe('PostgreSQL Aurora Configuration', () => {
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
// Reset all mocks
|
|
24
|
-
rdsMock.reset();
|
|
25
|
-
secretsManagerMock.reset();
|
|
26
|
-
ec2Mock.reset();
|
|
27
|
-
kmsMock.reset();
|
|
28
|
-
stsMock.reset();
|
|
29
|
-
|
|
30
|
-
// Setup default AWS mocks for discovery
|
|
31
|
-
ec2Mock.on(DescribeVpcsCommand).resolves({
|
|
32
|
-
Vpcs: [{ VpcId: 'vpc-12345', IsDefault: true }]
|
|
33
|
-
});
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
// An account with a default VPC and two private + two public subnets.
|
|
28
|
+
const accountWithDefaultVpc = (overrides = {}) => ({
|
|
29
|
+
defaultVpcId: 'vpc-12345',
|
|
30
|
+
vpcCidr: '172.31.0.0/16',
|
|
31
|
+
defaultSecurityGroupId: 'sg-12345',
|
|
32
|
+
privateSubnetId1: 'subnet-private-1',
|
|
33
|
+
privateSubnetId2: 'subnet-private-2',
|
|
34
|
+
publicSubnetId1: 'subnet-public-1',
|
|
35
|
+
publicSubnetId2: 'subnet-public-2',
|
|
36
|
+
defaultRouteTableId: 'rtb-12345',
|
|
37
|
+
...overrides,
|
|
38
|
+
});
|
|
39
|
+
jest.mock('../domains/database/migration-engines', () => ({
|
|
40
|
+
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
const postgresApp = (postgres, extra = {}) => ({
|
|
44
|
+
name: 'test-app',
|
|
45
|
+
integrations: [],
|
|
46
|
+
vpc: { enable: true },
|
|
47
|
+
database: { postgres: { enable: true, ...postgres } },
|
|
48
|
+
...extra,
|
|
49
|
+
});
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
// The orchestrator logs each validation error, then throws a summary error.
|
|
52
|
+
async function expectValidationError(appDefinition, messagePattern) {
|
|
53
|
+
const logSpy = jest.spyOn(console, 'log');
|
|
54
|
+
try {
|
|
55
|
+
await expect(composeServerlessDefinition(appDefinition)).rejects.toThrow(
|
|
56
|
+
'Infrastructure validation failed'
|
|
57
|
+
);
|
|
58
|
+
const logged = logSpy.mock.calls.map((args) => args.join(' ')).join('\n');
|
|
59
|
+
expect(logged).toMatch(messagePattern);
|
|
60
|
+
} finally {
|
|
61
|
+
logSpy.mockRestore();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('PostgreSQL Aurora configuration (composer)', () => {
|
|
66
|
+
const originalSkip = process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
49
67
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
70
|
+
gatherDiscoveredResources.mockResolvedValue(accountWithDefaultVpc());
|
|
53
71
|
});
|
|
54
72
|
|
|
55
73
|
afterEach(() => {
|
|
56
74
|
jest.clearAllMocks();
|
|
57
|
-
|
|
75
|
+
if (originalSkip === undefined) {
|
|
76
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
77
|
+
} else {
|
|
78
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = originalSkip;
|
|
79
|
+
}
|
|
58
80
|
});
|
|
59
81
|
|
|
60
|
-
describe('
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
64
|
-
|
|
65
|
-
const appDefinition = {
|
|
82
|
+
describe('when postgres is not configured', () => {
|
|
83
|
+
it('adds no Aurora resources or database env vars', async () => {
|
|
84
|
+
const definition = await composeServerlessDefinition({
|
|
66
85
|
name: 'test-app',
|
|
67
86
|
integrations: [],
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
87
|
+
});
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
const resources = definition.resources.Resources;
|
|
90
|
+
expect(resources.FriggAuroraCluster).toBeUndefined();
|
|
91
|
+
expect(resources.FriggDBSecret).toBeUndefined();
|
|
73
92
|
expect(definition.provider.environment.DATABASE_URL).toBeUndefined();
|
|
74
|
-
expect(definition.provider.environment.DB_TYPE).toBeUndefined();
|
|
75
93
|
});
|
|
94
|
+
});
|
|
76
95
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const appDefinition = {
|
|
81
|
-
name: 'test-app',
|
|
82
|
-
integrations: [],
|
|
83
|
-
vpc: { enable: true, management: 'create-new' },
|
|
84
|
-
database: {
|
|
85
|
-
postgres: {
|
|
86
|
-
enable: true,
|
|
87
|
-
management: 'create-new',
|
|
88
|
-
databaseName: 'test_db',
|
|
89
|
-
masterUsername: 'test_admin',
|
|
90
|
-
scaling: {
|
|
91
|
-
minCapacity: 0.5,
|
|
92
|
-
maxCapacity: 1.0,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const discoveredResources = {
|
|
99
|
-
defaultVpcId: 'vpc-12345',
|
|
100
|
-
defaultSecurityGroupId: 'sg-12345',
|
|
101
|
-
privateSubnetId1: 'subnet-1',
|
|
102
|
-
privateSubnetId2: 'subnet-2',
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
106
|
-
|
|
107
|
-
// Should create Aurora cluster resources
|
|
108
|
-
expect(definition.resources.Resources.FriggAuroraCluster).toBeDefined();
|
|
109
|
-
expect(definition.resources.Resources.FriggAuroraCluster.Type).toBe('AWS::RDS::DBCluster');
|
|
110
|
-
expect(definition.resources.Resources.FriggAuroraCluster.Properties.Engine).toBe('aurora-postgresql');
|
|
111
|
-
expect(definition.resources.Resources.FriggAuroraCluster.Properties.DatabaseName).toBe('test_db');
|
|
112
|
-
|
|
113
|
-
// Should create Aurora instance
|
|
114
|
-
expect(definition.resources.Resources.FriggAuroraInstance).toBeDefined();
|
|
115
|
-
expect(definition.resources.Resources.FriggAuroraInstance.Properties.DBInstanceClass).toBe('db.serverless');
|
|
116
|
-
|
|
117
|
-
// Should create DB subnet group
|
|
118
|
-
expect(definition.resources.Resources.FriggDBSubnetGroup).toBeDefined();
|
|
119
|
-
|
|
120
|
-
// Should create security group
|
|
121
|
-
expect(definition.resources.Resources.FriggAuroraSecurityGroup).toBeDefined();
|
|
122
|
-
expect(definition.resources.Resources.FriggAuroraSecurityGroup.Properties.SecurityGroupIngress[0].FromPort).toBe(5432);
|
|
123
|
-
|
|
124
|
-
// Should create Secrets Manager secret
|
|
125
|
-
expect(definition.resources.Resources.FriggDatabaseSecret).toBeDefined();
|
|
126
|
-
|
|
127
|
-
// Should create secret attachment
|
|
128
|
-
expect(definition.resources.Resources.FriggSecretAttachment).toBeDefined();
|
|
129
|
-
|
|
130
|
-
// Should set environment variables
|
|
131
|
-
expect(definition.provider.environment.DATABASE_URL).toBeDefined();
|
|
132
|
-
expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
|
|
133
|
-
|
|
134
|
-
// Should add IAM permissions for Secrets Manager
|
|
135
|
-
const secretsManagerPolicy = definition.provider.iamRoleStatements.find(
|
|
136
|
-
stmt => stmt.Action.includes('secretsmanager:GetSecretValue')
|
|
137
|
-
);
|
|
138
|
-
expect(secretsManagerPolicy).toBeDefined();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('should configure Aurora with custom settings', async () => {
|
|
142
|
-
// Skip discovery for create-new mode test
|
|
143
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
144
|
-
|
|
145
|
-
const appDefinition = {
|
|
146
|
-
name: 'test-app',
|
|
147
|
-
integrations: [],
|
|
148
|
-
vpc: { enable: true, management: 'create-new' },
|
|
149
|
-
database: {
|
|
150
|
-
postgres: {
|
|
151
|
-
enable: true,
|
|
152
|
-
management: 'create-new',
|
|
153
|
-
engineVersion: '14.6',
|
|
154
|
-
scaling: {
|
|
155
|
-
minCapacity: 1.0,
|
|
156
|
-
maxCapacity: 4.0,
|
|
157
|
-
},
|
|
158
|
-
backupRetentionDays: 14,
|
|
159
|
-
deletionProtection: false,
|
|
160
|
-
enablePerformanceInsights: true,
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
166
|
-
|
|
167
|
-
const cluster = definition.resources.Resources.FriggAuroraCluster;
|
|
168
|
-
expect(cluster.Properties.EngineVersion).toBe('14.6');
|
|
169
|
-
expect(cluster.Properties.ServerlessV2ScalingConfiguration.MinCapacity).toBe(1.0);
|
|
170
|
-
expect(cluster.Properties.ServerlessV2ScalingConfiguration.MaxCapacity).toBe(4.0);
|
|
171
|
-
expect(cluster.Properties.BackupRetentionPeriod).toBe(14);
|
|
172
|
-
expect(cluster.Properties.DeletionProtection).toBe(false);
|
|
173
|
-
|
|
174
|
-
const instance = definition.resources.Resources.FriggAuroraInstance;
|
|
175
|
-
expect(instance.Properties.EnablePerformanceInsights).toBe(true);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test('should set deletion protection by default', async () => {
|
|
179
|
-
// Skip discovery for create-new mode test
|
|
180
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
181
|
-
|
|
182
|
-
const appDefinition = {
|
|
183
|
-
name: 'test-app',
|
|
184
|
-
integrations: [],
|
|
185
|
-
vpc: { enable: true, management: 'create-new' },
|
|
186
|
-
database: {
|
|
187
|
-
postgres: {
|
|
188
|
-
enable: true,
|
|
189
|
-
management: 'create-new',
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
195
|
-
|
|
196
|
-
const cluster = definition.resources.Resources.FriggAuroraCluster;
|
|
197
|
-
expect(cluster.Properties.DeletionProtection).toBe(true);
|
|
198
|
-
expect(cluster.DeletionPolicy).toBe('Snapshot');
|
|
199
|
-
expect(cluster.UpdateReplacePolicy).toBe('Snapshot');
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test('should enable CloudWatch Logs exports', async () => {
|
|
203
|
-
// Skip discovery for create-new mode test
|
|
204
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
205
|
-
|
|
206
|
-
const appDefinition = {
|
|
96
|
+
describe("management: 'external' (bring your own DATABASE_URL)", () => {
|
|
97
|
+
it('creates no Aurora resources and needs no VPC', async () => {
|
|
98
|
+
const definition = await composeServerlessDefinition({
|
|
207
99
|
name: 'test-app',
|
|
208
100
|
integrations: [],
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
postgres: {
|
|
212
|
-
enable: true,
|
|
213
|
-
management: 'create-new',
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
219
|
-
|
|
220
|
-
const cluster = definition.resources.Resources.FriggAuroraCluster;
|
|
221
|
-
expect(cluster.Properties.EnableCloudwatchLogsExports).toContain('postgresql');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('should throw error when use-existing without cluster identifier', async () => {
|
|
225
|
-
// Skip discovery and mock RDS to return empty clusters
|
|
226
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
101
|
+
database: { postgres: { enable: true, management: 'external' } },
|
|
102
|
+
});
|
|
227
103
|
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
management: 'use-existing',
|
|
236
|
-
// Missing clusterIdentifier
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// Should throw error during configuration
|
|
242
|
-
await expect(composeServerlessDefinition(appDefinition)).rejects.toThrow();
|
|
104
|
+
const resourceTypes = Object.values(definition.resources.Resources).map(
|
|
105
|
+
(r) => r.Type
|
|
106
|
+
);
|
|
107
|
+
expect(resourceTypes).not.toContain('AWS::RDS::DBCluster');
|
|
108
|
+
expect(resourceTypes).not.toContain('AWS::RDS::DBInstance');
|
|
109
|
+
expect(resourceTypes).not.toContain('AWS::EC2::VPC');
|
|
110
|
+
expect(definition.provider.vpc).toBeUndefined();
|
|
243
111
|
});
|
|
244
112
|
});
|
|
245
113
|
|
|
246
|
-
describe('
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
114
|
+
describe("management: 'managed' (create Aurora in the stack)", () => {
|
|
115
|
+
let definition;
|
|
116
|
+
let resources;
|
|
250
117
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
postgres: {
|
|
257
|
-
enable: true,
|
|
258
|
-
management: 'create-new',
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
264
|
-
|
|
265
|
-
// Should have standard env vars
|
|
266
|
-
expect(definition.provider.environment.STAGE).toBe('${opt:stage, "dev"}');
|
|
267
|
-
expect(definition.provider.environment.AWS_NODEJS_CONNECTION_REUSE_ENABLED).toBe(1);
|
|
268
|
-
|
|
269
|
-
// Should have DATABASE_URL and DB_TYPE
|
|
270
|
-
expect(definition.provider.environment.DATABASE_URL).toBeDefined();
|
|
271
|
-
expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
|
|
118
|
+
beforeEach(async () => {
|
|
119
|
+
definition = await composeServerlessDefinition(
|
|
120
|
+
postgresApp({ management: 'managed' })
|
|
121
|
+
);
|
|
122
|
+
resources = definition.resources.Resources;
|
|
272
123
|
});
|
|
273
124
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
125
|
+
it('creates an Aurora Serverless v2 PostgreSQL cluster and instance', () => {
|
|
126
|
+
const cluster = resources.FriggAuroraCluster;
|
|
127
|
+
expect(cluster.Type).toBe('AWS::RDS::DBCluster');
|
|
128
|
+
expect(cluster.Properties.Engine).toBe('aurora-postgresql');
|
|
129
|
+
expect(cluster.Properties.Port).toBe(5432);
|
|
130
|
+
expect(cluster.Properties.ServerlessV2ScalingConfiguration).toEqual({
|
|
131
|
+
MinCapacity: 0.5,
|
|
132
|
+
MaxCapacity: 4,
|
|
133
|
+
});
|
|
284
134
|
|
|
285
|
-
|
|
286
|
-
expect(
|
|
135
|
+
const instance = resources.FriggAuroraInstance;
|
|
136
|
+
expect(instance.Type).toBe('AWS::RDS::DBInstance');
|
|
137
|
+
expect(instance.Properties.DBInstanceClass).toBe('db.serverless');
|
|
138
|
+
expect(instance.Properties.DBClusterIdentifier).toEqual({
|
|
139
|
+
Ref: 'FriggAuroraCluster',
|
|
140
|
+
});
|
|
141
|
+
expect(instance.Properties.PubliclyAccessible).toBe(false);
|
|
287
142
|
});
|
|
288
|
-
});
|
|
289
143
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// Skip discovery for create-new mode test
|
|
293
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
294
|
-
|
|
295
|
-
const appDefinition = {
|
|
296
|
-
name: 'test-app',
|
|
297
|
-
integrations: [],
|
|
298
|
-
vpc: { enable: true, management: 'create-new' },
|
|
299
|
-
database: {
|
|
300
|
-
postgres: {
|
|
301
|
-
enable: true,
|
|
302
|
-
management: 'create-new',
|
|
303
|
-
databaseName: 'my_db',
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
309
|
-
|
|
310
|
-
const databaseUrl = definition.provider.environment.DATABASE_URL;
|
|
311
|
-
expect(databaseUrl['Fn::Sub']).toBeDefined();
|
|
312
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('postgresql://');
|
|
313
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('${Username}');
|
|
314
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('${Password}');
|
|
315
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('${Endpoint}');
|
|
316
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('${Port}');
|
|
317
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('${DatabaseName}');
|
|
318
|
-
|
|
319
|
-
const substitutions = databaseUrl['Fn::Sub'][1];
|
|
320
|
-
expect(substitutions.Username).toBeDefined();
|
|
321
|
-
expect(substitutions.Password).toBeDefined();
|
|
322
|
-
expect(substitutions.Endpoint).toBeDefined();
|
|
323
|
-
expect(substitutions.Port).toBeDefined();
|
|
324
|
-
expect(substitutions.DatabaseName).toBe('my_db');
|
|
144
|
+
it('snapshots the cluster on stack deletion', () => {
|
|
145
|
+
expect(resources.FriggAuroraCluster.DeletionPolicy).toBe('Snapshot');
|
|
325
146
|
});
|
|
326
|
-
});
|
|
327
147
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
148
|
+
it('uses sensible defaults for optional settings', () => {
|
|
149
|
+
const props = resources.FriggAuroraCluster.Properties;
|
|
150
|
+
expect(props.DatabaseName).toBe('frigg');
|
|
151
|
+
expect(props.EngineVersion).toBe('15.13');
|
|
152
|
+
expect(props.BackupRetentionPeriod).toBe(7);
|
|
153
|
+
expect(props.PreferredBackupWindow).toBe('03:00-04:00');
|
|
332
154
|
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
vpc: { enable: true, management: 'create-new' },
|
|
337
|
-
database: {
|
|
338
|
-
postgres: {
|
|
339
|
-
enable: true,
|
|
340
|
-
management: 'create-new',
|
|
341
|
-
masterUsername: 'custom_admin',
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
347
|
-
|
|
348
|
-
const secret = definition.resources.Resources.FriggDatabaseSecret;
|
|
349
|
-
expect(secret.Properties.GenerateSecretString.SecretStringTemplate).toBe(
|
|
350
|
-
JSON.stringify({ username: 'custom_admin' })
|
|
155
|
+
const template = JSON.parse(
|
|
156
|
+
resources.FriggDBSecret.Properties.GenerateSecretString
|
|
157
|
+
.SecretStringTemplate
|
|
351
158
|
);
|
|
352
|
-
expect(
|
|
353
|
-
expect(secret.Properties.GenerateSecretString.PasswordLength).toBe(32);
|
|
159
|
+
expect(template.username).toBe('postgres');
|
|
354
160
|
});
|
|
355
161
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
integrations: [],
|
|
363
|
-
vpc: { enable: true, management: 'create-new' },
|
|
364
|
-
database: {
|
|
365
|
-
postgres: {
|
|
366
|
-
enable: true,
|
|
367
|
-
management: 'create-new',
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
373
|
-
|
|
374
|
-
const secret = definition.resources.Resources.FriggDatabaseSecret;
|
|
375
|
-
expect(secret.Properties.GenerateSecretString.ExcludeCharacters).toBe('"@/\\');
|
|
162
|
+
it('places the DB subnet group in the private subnets', () => {
|
|
163
|
+
expect(resources.FriggDBSubnetGroup.Type).toBe('AWS::RDS::DBSubnetGroup');
|
|
164
|
+
expect(resources.FriggDBSubnetGroup.Properties.SubnetIds).toEqual([
|
|
165
|
+
'subnet-private-1',
|
|
166
|
+
'subnet-private-2',
|
|
167
|
+
]);
|
|
376
168
|
});
|
|
377
169
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const appDefinition = {
|
|
383
|
-
name: 'test-app',
|
|
384
|
-
integrations: [],
|
|
385
|
-
vpc: { enable: true, management: 'create-new' },
|
|
386
|
-
database: {
|
|
387
|
-
postgres: {
|
|
388
|
-
enable: true,
|
|
389
|
-
management: 'create-new',
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
395
|
-
|
|
396
|
-
const secret = definition.resources.Resources.FriggDatabaseSecret;
|
|
397
|
-
const tags = secret.Properties.Tags;
|
|
398
|
-
|
|
399
|
-
expect(tags.find(t => t.Key === 'ManagedBy' && t.Value === 'Frigg')).toBeDefined();
|
|
400
|
-
expect(tags.find(t => t.Key === 'Service' && t.Value === '${self:service}')).toBeDefined();
|
|
401
|
-
expect(tags.find(t => t.Key === 'Stage' && t.Value === '${self:provider.stage}')).toBeDefined();
|
|
402
|
-
});
|
|
403
|
-
});
|
|
170
|
+
it('generates credentials in Secrets Manager with a URL-safe password', () => {
|
|
171
|
+
const secret = resources.FriggDBSecret;
|
|
172
|
+
expect(secret.Type).toBe('AWS::SecretsManager::Secret');
|
|
404
173
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
174
|
+
const generate = secret.Properties.GenerateSecretString;
|
|
175
|
+
expect(generate.GenerateStringKey).toBe('password');
|
|
176
|
+
expect(generate.PasswordLength).toBe(32);
|
|
177
|
+
// Characters with special meaning in a connection URL are excluded.
|
|
178
|
+
for (const ch of ['"', '@', ':', '/', '?', '#', '%']) {
|
|
179
|
+
expect(generate.ExcludeCharacters).toContain(ch);
|
|
180
|
+
}
|
|
409
181
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
vpc: { enable: true, management: 'create-new' },
|
|
414
|
-
database: {
|
|
415
|
-
postgres: {
|
|
416
|
-
enable: true,
|
|
417
|
-
management: 'create-new',
|
|
418
|
-
},
|
|
419
|
-
},
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
423
|
-
|
|
424
|
-
const sg = definition.resources.Resources.FriggAuroraSecurityGroup;
|
|
425
|
-
const ingressRule = sg.Properties.SecurityGroupIngress[0];
|
|
426
|
-
|
|
427
|
-
expect(ingressRule.IpProtocol).toBe('tcp');
|
|
428
|
-
expect(ingressRule.FromPort).toBe(5432);
|
|
429
|
-
expect(ingressRule.ToPort).toBe(5432);
|
|
430
|
-
expect(ingressRule.Description).toContain('PostgreSQL');
|
|
182
|
+
expect(secret.Properties.Tags).toEqual(
|
|
183
|
+
expect.arrayContaining([{ Key: 'ManagedBy', Value: 'Frigg' }])
|
|
184
|
+
);
|
|
431
185
|
});
|
|
432
186
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const appDefinition = {
|
|
438
|
-
name: 'test-app',
|
|
439
|
-
integrations: [],
|
|
440
|
-
vpc: { enable: true, management: 'create-new' },
|
|
441
|
-
database: {
|
|
442
|
-
postgres: {
|
|
443
|
-
enable: true,
|
|
444
|
-
management: 'create-new',
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
450
|
-
|
|
451
|
-
const sg = definition.resources.Resources.FriggAuroraSecurityGroup;
|
|
452
|
-
const tags = sg.Properties.Tags;
|
|
187
|
+
it('sets DATABASE_URL from the cluster endpoint and the secret', () => {
|
|
188
|
+
const databaseUrl = definition.provider.environment.DATABASE_URL;
|
|
189
|
+
expect(databaseUrl).toBeDefined();
|
|
453
190
|
|
|
454
|
-
|
|
191
|
+
const serialized = JSON.stringify(databaseUrl);
|
|
192
|
+
expect(serialized).toContain('postgresql://');
|
|
193
|
+
expect(serialized).toContain('FriggAuroraCluster');
|
|
194
|
+
expect(serialized).toContain('FriggDBSecret');
|
|
455
195
|
});
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
describe('IAM Permissions', () => {
|
|
459
|
-
test('should add Secrets Manager permissions', async () => {
|
|
460
|
-
// Skip discovery for create-new mode test
|
|
461
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
462
196
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
enable: true,
|
|
470
|
-
management: 'create-new',
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
476
|
-
|
|
477
|
-
const secretsManagerPolicy = definition.provider.iamRoleStatements.find(
|
|
478
|
-
stmt => stmt.Action.includes('secretsmanager:GetSecretValue')
|
|
197
|
+
it('grants Lambda read access to the database secret', () => {
|
|
198
|
+
const statement = definition.provider.iamRoleStatements.find(
|
|
199
|
+
(s) =>
|
|
200
|
+
Array.isArray(s.Action) &&
|
|
201
|
+
s.Action.includes('secretsmanager:GetSecretValue') &&
|
|
202
|
+
JSON.stringify(s.Resource).includes('FriggDBSecret')
|
|
479
203
|
);
|
|
204
|
+
expect(statement).toBeDefined();
|
|
205
|
+
expect(statement.Effect).toBe('Allow');
|
|
206
|
+
});
|
|
480
207
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
expect(
|
|
484
|
-
expect(
|
|
208
|
+
it('lets the Lambda security group reach PostgreSQL on 5432', () => {
|
|
209
|
+
const rule = resources.FriggAuroraIngressRule;
|
|
210
|
+
expect(rule.Type).toBe('AWS::EC2::SecurityGroupIngress');
|
|
211
|
+
expect(rule.Properties).toEqual(
|
|
212
|
+
expect.objectContaining({
|
|
213
|
+
IpProtocol: 'tcp',
|
|
214
|
+
FromPort: 5432,
|
|
215
|
+
ToPort: 5432,
|
|
216
|
+
GroupId: { Ref: 'FriggLambdaSecurityGroup' },
|
|
217
|
+
SourceSecurityGroupId: { Ref: 'FriggLambdaSecurityGroup' },
|
|
218
|
+
})
|
|
219
|
+
);
|
|
485
220
|
});
|
|
486
221
|
});
|
|
487
222
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const cluster = definition.resources.Resources.FriggAuroraCluster;
|
|
509
|
-
expect(cluster.Properties.EngineVersion).toBe('15.3');
|
|
510
|
-
expect(cluster.Properties.DatabaseName).toBe('frigg_db');
|
|
511
|
-
expect(cluster.Properties.ServerlessV2ScalingConfiguration.MinCapacity).toBe(0.5);
|
|
512
|
-
expect(cluster.Properties.ServerlessV2ScalingConfiguration.MaxCapacity).toBe(1.0);
|
|
513
|
-
expect(cluster.Properties.BackupRetentionPeriod).toBe(7);
|
|
514
|
-
expect(cluster.Properties.PreferredBackupWindow).toBe('03:00-04:00');
|
|
515
|
-
expect(cluster.Properties.DeletionProtection).toBe(true);
|
|
516
|
-
|
|
517
|
-
const secret = definition.resources.Resources.FriggDatabaseSecret;
|
|
518
|
-
const secretTemplate = JSON.parse(secret.Properties.GenerateSecretString.SecretStringTemplate);
|
|
519
|
-
expect(secretTemplate.username).toBe('frigg_admin');
|
|
520
|
-
|
|
521
|
-
const instance = definition.resources.Resources.FriggAuroraInstance;
|
|
522
|
-
expect(instance.Properties.EnablePerformanceInsights).toBe(false);
|
|
223
|
+
it('applies custom Aurora settings', async () => {
|
|
224
|
+
const definition = await composeServerlessDefinition(
|
|
225
|
+
postgresApp({
|
|
226
|
+
management: 'managed',
|
|
227
|
+
engineVersion: '16.4',
|
|
228
|
+
database: 'my_db',
|
|
229
|
+
username: 'custom_admin',
|
|
230
|
+
minCapacity: 1,
|
|
231
|
+
maxCapacity: 8,
|
|
232
|
+
})
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const resources = definition.resources.Resources;
|
|
236
|
+
const props = resources.FriggAuroraCluster.Properties;
|
|
237
|
+
expect(props.EngineVersion).toBe('16.4');
|
|
238
|
+
expect(props.DatabaseName).toBe('my_db');
|
|
239
|
+
expect(props.ServerlessV2ScalingConfiguration).toEqual({
|
|
240
|
+
MinCapacity: 1,
|
|
241
|
+
MaxCapacity: 8,
|
|
523
242
|
});
|
|
243
|
+
expect(
|
|
244
|
+
JSON.parse(
|
|
245
|
+
resources.FriggDBSecret.Properties.GenerateSecretString
|
|
246
|
+
.SecretStringTemplate
|
|
247
|
+
)
|
|
248
|
+
).toEqual({ username: 'custom_admin' });
|
|
524
249
|
});
|
|
525
250
|
|
|
526
|
-
describe(
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
integrations: [],
|
|
534
|
-
// VPC not enabled
|
|
535
|
-
database: {
|
|
536
|
-
postgres: {
|
|
537
|
-
enable: true,
|
|
538
|
-
management: 'create-new',
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
await expect(composeServerlessDefinition(appDefinition)).rejects.toThrow(
|
|
544
|
-
/Aurora PostgreSQL requires VPC deployment/
|
|
251
|
+
describe("management: 'use-existing'", () => {
|
|
252
|
+
it('points the app at the provided endpoint without creating a cluster', async () => {
|
|
253
|
+
const definition = await composeServerlessDefinition(
|
|
254
|
+
postgresApp({
|
|
255
|
+
management: 'use-existing',
|
|
256
|
+
endpoint: 'existing.cluster.us-east-1.rds.amazonaws.com',
|
|
257
|
+
})
|
|
545
258
|
);
|
|
546
|
-
});
|
|
547
259
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
Subnets: [
|
|
552
|
-
{ SubnetId: 'subnet-1', AvailabilityZone: 'us-east-1a', MapPublicIpOnLaunch: false }
|
|
553
|
-
]
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
rdsMock.on(DescribeDBClustersCommand).resolves({ DBClusters: [] });
|
|
557
|
-
rdsMock.on(DescribeDBSubnetGroupsCommand).resolves({ DBSubnetGroups: [] });
|
|
558
|
-
secretsManagerMock.on(ListSecretsCommand).resolves({ SecretList: [] });
|
|
559
|
-
|
|
560
|
-
const appDefinition = {
|
|
561
|
-
name: 'test-app',
|
|
562
|
-
integrations: [],
|
|
563
|
-
vpc: { enable: true }, // Use default 'discover' mode to trigger subnet validation
|
|
564
|
-
database: {
|
|
565
|
-
postgres: {
|
|
566
|
-
enable: true,
|
|
567
|
-
management: 'create-new',
|
|
568
|
-
},
|
|
569
|
-
},
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
await expect(composeServerlessDefinition(appDefinition)).rejects.toThrow(
|
|
573
|
-
/Aurora PostgreSQL requires at least 2 private subnets/
|
|
260
|
+
expect(definition.resources.Resources.FriggAuroraCluster).toBeUndefined();
|
|
261
|
+
expect(definition.provider.environment.DATABASE_HOST).toBe(
|
|
262
|
+
'existing.cluster.us-east-1.rds.amazonaws.com'
|
|
574
263
|
);
|
|
264
|
+
expect(definition.provider.environment.DATABASE_PORT).toBe('5432');
|
|
575
265
|
});
|
|
576
266
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const appDefinition = {
|
|
582
|
-
name: 'test-app',
|
|
583
|
-
integrations: [],
|
|
584
|
-
vpc: { enable: true, management: 'create-new' },
|
|
585
|
-
database: {
|
|
586
|
-
postgres: {
|
|
587
|
-
enable: true,
|
|
588
|
-
management: 'use-existing',
|
|
589
|
-
// Missing clusterIdentifier
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
await expect(composeServerlessDefinition(appDefinition)).rejects.toThrow(
|
|
595
|
-
/clusterIdentifier/
|
|
267
|
+
it('rejects a definition without an endpoint', async () => {
|
|
268
|
+
await expectValidationError(
|
|
269
|
+
postgresApp({ management: 'use-existing' }),
|
|
270
|
+
/database\.postgres\.endpoint is required/
|
|
596
271
|
);
|
|
597
272
|
});
|
|
598
273
|
});
|
|
599
274
|
|
|
600
|
-
describe('
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
Port: 5432,
|
|
610
|
-
DatabaseName: 'discovered_db',
|
|
611
|
-
DBSubnetGroup: 'discovered-subnet-group',
|
|
612
|
-
VpcSecurityGroups: [{ VpcSecurityGroupId: 'sg-discovered' }],
|
|
613
|
-
TagList: [
|
|
614
|
-
{ Key: 'ManagedBy', Value: 'Frigg' },
|
|
615
|
-
{ Key: 'Service', Value: 'test-app' },
|
|
616
|
-
{ Key: 'Stage', Value: 'dev' }
|
|
617
|
-
]
|
|
618
|
-
}]
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
rdsMock.on(DescribeDBSubnetGroupsCommand).resolves({
|
|
622
|
-
DBSubnetGroups: [{
|
|
623
|
-
DBSubnetGroupName: 'discovered-subnet-group',
|
|
624
|
-
VpcId: 'vpc-12345',
|
|
625
|
-
Subnets: [
|
|
626
|
-
{ SubnetIdentifier: 'subnet-1' },
|
|
627
|
-
{ SubnetIdentifier: 'subnet-2' }
|
|
628
|
-
]
|
|
629
|
-
}]
|
|
630
|
-
});
|
|
275
|
+
describe("management: 'discover' (the default)", () => {
|
|
276
|
+
it('uses a discovered Aurora cluster instead of creating one', async () => {
|
|
277
|
+
gatherDiscoveredResources.mockResolvedValue(
|
|
278
|
+
accountWithDefaultVpc({
|
|
279
|
+
auroraClusterEndpoint:
|
|
280
|
+
'discovered.cluster-abc.us-east-1.rds.amazonaws.com',
|
|
281
|
+
auroraPort: 5432,
|
|
282
|
+
})
|
|
283
|
+
);
|
|
631
284
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
Name: 'frigg-db-secret',
|
|
636
|
-
Tags: [
|
|
637
|
-
{ Key: 'ManagedBy', Value: 'Frigg' },
|
|
638
|
-
{ Key: 'Service', Value: 'test-app' },
|
|
639
|
-
{ Key: 'Stage', Value: 'dev' }
|
|
640
|
-
]
|
|
641
|
-
}]
|
|
642
|
-
});
|
|
285
|
+
const definition = await composeServerlessDefinition(
|
|
286
|
+
postgresApp({ management: 'discover' })
|
|
287
|
+
);
|
|
643
288
|
|
|
644
|
-
const appDefinition = {
|
|
645
|
-
name: 'test-app',
|
|
646
|
-
integrations: [],
|
|
647
|
-
vpc: { enable: true },
|
|
648
|
-
database: {
|
|
649
|
-
postgres: {
|
|
650
|
-
enable: true,
|
|
651
|
-
management: 'discover',
|
|
652
|
-
},
|
|
653
|
-
},
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
657
|
-
|
|
658
|
-
// Should use discovered cluster, not create new one
|
|
659
289
|
expect(definition.resources.Resources.FriggAuroraCluster).toBeUndefined();
|
|
660
|
-
expect(definition.provider.environment.
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
test('should create new cluster when none found', async () => {
|
|
665
|
-
// Mock no clusters found
|
|
666
|
-
rdsMock.on(DescribeDBClustersCommand).resolves({ DBClusters: [] });
|
|
667
|
-
rdsMock.on(DescribeDBSubnetGroupsCommand).resolves({ DBSubnetGroups: [] });
|
|
668
|
-
secretsManagerMock.on(ListSecretsCommand).resolves({ SecretList: [] });
|
|
669
|
-
|
|
670
|
-
const appDefinition = {
|
|
671
|
-
name: 'test-app',
|
|
672
|
-
integrations: [],
|
|
673
|
-
vpc: { enable: true },
|
|
674
|
-
database: {
|
|
675
|
-
postgres: {
|
|
676
|
-
enable: true,
|
|
677
|
-
management: 'discover',
|
|
678
|
-
},
|
|
679
|
-
},
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
683
|
-
|
|
684
|
-
// Should create new cluster
|
|
685
|
-
expect(definition.resources.Resources.FriggAuroraCluster).toBeDefined();
|
|
686
|
-
expect(definition.resources.Resources.FriggAuroraCluster.Type).toBe('AWS::RDS::DBCluster');
|
|
290
|
+
expect(definition.provider.environment.DATABASE_HOST).toBe(
|
|
291
|
+
'discovered.cluster-abc.us-east-1.rds.amazonaws.com'
|
|
292
|
+
);
|
|
687
293
|
});
|
|
688
294
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
DBClusterIdentifier: 'discovered-cluster',
|
|
694
|
-
Engine: 'aurora-postgresql',
|
|
695
|
-
Status: 'available',
|
|
696
|
-
Endpoint: 'discovered.cluster.us-east-1.rds.amazonaws.com',
|
|
697
|
-
Port: 5432,
|
|
698
|
-
DatabaseName: 'discovered_db',
|
|
699
|
-
DBSubnetGroup: 'discovered-subnet-group',
|
|
700
|
-
VpcSecurityGroups: [{ VpcSecurityGroupId: 'sg-discovered' }],
|
|
701
|
-
TagList: [
|
|
702
|
-
{ Key: 'ManagedBy', Value: 'Frigg' }
|
|
703
|
-
]
|
|
704
|
-
}]
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
rdsMock.on(DescribeDBSubnetGroupsCommand).resolves({
|
|
708
|
-
DBSubnetGroups: [{
|
|
709
|
-
DBSubnetGroupName: 'discovered-subnet-group',
|
|
710
|
-
VpcId: 'vpc-12345',
|
|
711
|
-
Subnets: [
|
|
712
|
-
{ SubnetIdentifier: 'subnet-1' },
|
|
713
|
-
{ SubnetIdentifier: 'subnet-2' }
|
|
714
|
-
]
|
|
715
|
-
}]
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
secretsManagerMock.on(ListSecretsCommand).resolves({
|
|
719
|
-
SecretList: [{
|
|
720
|
-
ARN: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:discovered-secret',
|
|
721
|
-
Name: 'discovered-secret',
|
|
722
|
-
Tags: [
|
|
723
|
-
{ Key: 'ManagedBy', Value: 'Frigg' }
|
|
724
|
-
]
|
|
725
|
-
}]
|
|
726
|
-
});
|
|
295
|
+
it('creates a cluster in the stack when none is discovered', async () => {
|
|
296
|
+
const definition = await composeServerlessDefinition(
|
|
297
|
+
postgresApp({ management: 'discover' })
|
|
298
|
+
);
|
|
727
299
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
integrations: [],
|
|
731
|
-
vpc: { enable: true },
|
|
732
|
-
database: {
|
|
733
|
-
postgres: {
|
|
734
|
-
enable: true,
|
|
735
|
-
management: 'discover',
|
|
736
|
-
},
|
|
737
|
-
},
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
741
|
-
|
|
742
|
-
// Should reference discovered secret in IAM policy
|
|
743
|
-
const secretsManagerPolicy = definition.provider.iamRoleStatements.find(
|
|
744
|
-
stmt => stmt.Action.includes('secretsmanager:GetSecretValue')
|
|
300
|
+
expect(definition.resources.Resources.FriggAuroraCluster.Type).toBe(
|
|
301
|
+
'AWS::RDS::DBCluster'
|
|
745
302
|
);
|
|
746
|
-
expect(secretsManagerPolicy).toBeDefined();
|
|
747
|
-
expect(secretsManagerPolicy.Resource).toContain('discovered-secret');
|
|
748
303
|
});
|
|
749
304
|
});
|
|
750
305
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
Status: 'available',
|
|
759
|
-
Endpoint: 'integration.cluster.us-east-1.rds.amazonaws.com',
|
|
760
|
-
Port: 5432,
|
|
761
|
-
DatabaseName: 'integration_db',
|
|
762
|
-
DBSubnetGroup: 'integration-subnet-group',
|
|
763
|
-
VpcSecurityGroups: [{ VpcSecurityGroupId: 'sg-integration' }],
|
|
764
|
-
TagList: [{ Key: 'ManagedBy', Value: 'Frigg' }]
|
|
765
|
-
}]
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
rdsMock.on(DescribeDBSubnetGroupsCommand).resolves({
|
|
769
|
-
DBSubnetGroups: [{
|
|
770
|
-
DBSubnetGroupName: 'integration-subnet-group',
|
|
771
|
-
VpcId: 'vpc-12345',
|
|
772
|
-
Subnets: [
|
|
773
|
-
{ SubnetIdentifier: 'subnet-1' },
|
|
774
|
-
{ SubnetIdentifier: 'subnet-2' }
|
|
775
|
-
]
|
|
776
|
-
}]
|
|
777
|
-
});
|
|
778
|
-
|
|
779
|
-
secretsManagerMock.on(ListSecretsCommand).resolves({
|
|
780
|
-
SecretList: [{
|
|
781
|
-
ARN: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:integration-secret',
|
|
782
|
-
Name: 'integration-secret',
|
|
783
|
-
Tags: [{ Key: 'ManagedBy', Value: 'Frigg' }]
|
|
784
|
-
}]
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
const appDefinition = {
|
|
788
|
-
name: 'test-app',
|
|
789
|
-
integrations: [],
|
|
790
|
-
vpc: { enable: true },
|
|
791
|
-
database: {
|
|
792
|
-
postgres: {
|
|
793
|
-
enable: true,
|
|
794
|
-
management: 'discover',
|
|
795
|
-
},
|
|
796
|
-
},
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
800
|
-
|
|
801
|
-
// DATABASE_URL should reference discovered endpoint
|
|
802
|
-
const databaseUrl = definition.provider.environment.DATABASE_URL;
|
|
803
|
-
expect(databaseUrl['Fn::Sub']).toBeDefined();
|
|
804
|
-
expect(databaseUrl['Fn::Sub'][0]).toContain('integration.cluster.us-east-1.rds.amazonaws.com');
|
|
805
|
-
});
|
|
806
|
-
|
|
807
|
-
test('should create Secrets Manager VPC endpoint when Aurora enabled', async () => {
|
|
808
|
-
// Skip discovery for create-new mode test
|
|
809
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
810
|
-
|
|
811
|
-
const appDefinition = {
|
|
812
|
-
name: 'test-app',
|
|
813
|
-
integrations: [],
|
|
814
|
-
vpc: { enable: true, management: 'create-new' },
|
|
815
|
-
database: {
|
|
816
|
-
postgres: {
|
|
817
|
-
enable: true,
|
|
818
|
-
management: 'create-new',
|
|
819
|
-
},
|
|
820
|
-
},
|
|
821
|
-
};
|
|
822
|
-
|
|
823
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
824
|
-
|
|
825
|
-
// Should create Secrets Manager VPC endpoint
|
|
826
|
-
// Note: For 'create-new' VPC mode, the resource is named FriggSecretsManagerVPCEndpoint
|
|
827
|
-
expect(definition.resources.Resources.FriggSecretsManagerVPCEndpoint).toBeDefined();
|
|
828
|
-
expect(definition.resources.Resources.FriggSecretsManagerVPCEndpoint.Type).toBe('AWS::EC2::VPCEndpoint');
|
|
829
|
-
expect(definition.resources.Resources.FriggSecretsManagerVPCEndpoint.Properties.ServiceName).toContain('secretsmanager');
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
test('should use correct security group source in create-new VPC mode', async () => {
|
|
833
|
-
// Skip discovery for create-new mode test
|
|
834
|
-
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
835
|
-
|
|
836
|
-
const appDefinition = {
|
|
837
|
-
name: 'test-app',
|
|
838
|
-
integrations: [],
|
|
839
|
-
vpc: { enable: true, management: 'create-new' },
|
|
840
|
-
database: {
|
|
841
|
-
postgres: {
|
|
842
|
-
enable: true,
|
|
843
|
-
management: 'create-new',
|
|
844
|
-
},
|
|
845
|
-
},
|
|
846
|
-
};
|
|
847
|
-
|
|
848
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
849
|
-
|
|
850
|
-
const sg = definition.resources.Resources.FriggAuroraSecurityGroup;
|
|
851
|
-
const ingressRule = sg.Properties.SecurityGroupIngress[0];
|
|
852
|
-
|
|
853
|
-
// Should reference FriggLambdaSecurityGroup (created by VPC)
|
|
854
|
-
expect(ingressRule.SourceSecurityGroupId).toEqual({ Ref: 'FriggLambdaSecurityGroup' });
|
|
855
|
-
});
|
|
306
|
+
it('rejects an unknown management mode', async () => {
|
|
307
|
+
// 'create-new' was the pre-2.0 spelling of 'managed'.
|
|
308
|
+
await expectValidationError(
|
|
309
|
+
postgresApp({ management: 'create-new' }),
|
|
310
|
+
/Invalid database\.postgres\.management: "create-new"/
|
|
311
|
+
);
|
|
312
|
+
});
|
|
856
313
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
rdsMock.on(DescribeDBClustersCommand).resolves({
|
|
860
|
-
DBClusters: [{
|
|
861
|
-
DBClusterIdentifier: 'iam-test-cluster',
|
|
862
|
-
Engine: 'aurora-postgresql',
|
|
863
|
-
Status: 'available',
|
|
864
|
-
Endpoint: 'iam.cluster.us-east-1.rds.amazonaws.com',
|
|
865
|
-
Port: 5432,
|
|
866
|
-
DatabaseName: 'iam_db',
|
|
867
|
-
DBSubnetGroup: 'iam-subnet-group',
|
|
868
|
-
VpcSecurityGroups: [{ VpcSecurityGroupId: 'sg-iam' }],
|
|
869
|
-
TagList: [{ Key: 'ManagedBy', Value: 'Frigg' }]
|
|
870
|
-
}]
|
|
871
|
-
});
|
|
314
|
+
it('skips Aurora entirely under `frigg start` (FRIGG_SKIP_AWS_DISCOVERY)', async () => {
|
|
315
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
872
316
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
VpcId: 'vpc-12345',
|
|
877
|
-
Subnets: [
|
|
878
|
-
{ SubnetIdentifier: 'subnet-1' },
|
|
879
|
-
{ SubnetIdentifier: 'subnet-2' }
|
|
880
|
-
]
|
|
881
|
-
}]
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
secretsManagerMock.on(ListSecretsCommand).resolves({
|
|
885
|
-
SecretList: [{
|
|
886
|
-
ARN: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:specific-iam-secret-abc123',
|
|
887
|
-
Name: 'specific-iam-secret',
|
|
888
|
-
Tags: [{ Key: 'ManagedBy', Value: 'Frigg' }]
|
|
889
|
-
}]
|
|
890
|
-
});
|
|
317
|
+
const definition = await composeServerlessDefinition(
|
|
318
|
+
postgresApp({ management: 'managed' })
|
|
319
|
+
);
|
|
891
320
|
|
|
892
|
-
|
|
893
|
-
name: 'test-app',
|
|
894
|
-
integrations: [],
|
|
895
|
-
vpc: { enable: true },
|
|
896
|
-
database: {
|
|
897
|
-
postgres: {
|
|
898
|
-
enable: true,
|
|
899
|
-
management: 'discover',
|
|
900
|
-
},
|
|
901
|
-
},
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
const definition = await composeServerlessDefinition(appDefinition);
|
|
905
|
-
|
|
906
|
-
// IAM policy should reference the specific discovered secret ARN
|
|
907
|
-
const secretsManagerPolicy = definition.provider.iamRoleStatements.find(
|
|
908
|
-
stmt => stmt.Action.includes('secretsmanager:GetSecretValue')
|
|
909
|
-
);
|
|
910
|
-
expect(secretsManagerPolicy).toBeDefined();
|
|
911
|
-
expect(secretsManagerPolicy.Resource).toContain('specific-iam-secret-abc123');
|
|
912
|
-
});
|
|
321
|
+
expect(definition.resources.Resources.FriggAuroraCluster).toBeUndefined();
|
|
913
322
|
});
|
|
914
323
|
});
|