/
index.js
executable file
·68 lines (57 loc) · 2.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
'use strict';
require('essentials');
require('log-node')();
const log = require('log').get('serverless:scripts');
const awsRequest = require('@serverless/test/aws-request');
const fsPromises = require('fs').promises;
const path = require('path');
const { SHARED_INFRA_TESTS_CLOUDFORMATION_STACK } = require('../../../test/utils/cludformation');
(async () => {
log.notice('Starting setup of integration infrastructure...');
const [cfnTemplate, kafkaServerProperties] = await Promise.all([
fsPromises.readFile(path.join(__dirname, 'cloudformation.yml'), 'utf8'),
fsPromises.readFile(path.join(__dirname, 'kafka.server.properties')),
]);
log.notice('Checking if integration tests CloudFormation stack already exists...');
try {
await awsRequest('CloudFormation', 'describeStacks', {
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
});
log.error('Integration tests CloudFormation stack already exists. Quitting.');
return;
} catch (e) {
if (e.code !== 'ValidationError') {
throw e;
}
}
log.notice('Integration tests CloudFormation does not exist. Continuing.');
const clusterName = 'integration-tests-msk-cluster';
const clusterConfName = 'integration-tests-msk-cluster-configuration';
log.notice('Creating MSK Cluster configuration...');
const clusterConfResponse = await awsRequest('Kafka', 'createConfiguration', {
Name: clusterConfName,
ServerProperties: kafkaServerProperties,
KafkaVersions: ['2.2.1'],
});
const clusterConfigurationArn = clusterConfResponse.Arn;
const clusterConfigurationRevision = clusterConfResponse.LatestRevision.Revision.toString();
log.notice('Deploying integration tests CloudFormation stack...');
await awsRequest('CloudFormation', 'createStack', {
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
TemplateBody: cfnTemplate,
Parameters: [
{ ParameterKey: 'ClusterName', ParameterValue: clusterName },
{ ParameterKey: 'ClusterConfigurationArn', ParameterValue: clusterConfigurationArn },
{
ParameterKey: 'ClusterConfigurationRevision',
ParameterValue: clusterConfigurationRevision,
},
],
});
await awsRequest('CloudFormation', 'waitFor', 'stackCreateComplete', {
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
});
log.notice('Deployed integration tests CloudFormation stack!');
log.notice('Setup of integration infrastructure finished');
})();