/
integration-teardown.js
executable file
·61 lines (55 loc) · 1.9 KB
/
integration-teardown.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
#!/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 {
SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
getDependencyStackOutputMap,
} = require('../../test/utils/cludformation');
(async () => {
log.notice('Starting teardown of integration infrastructure...');
const describeClustersResponse = await awsRequest('Kafka', 'listClusters');
const clusterConfArn =
describeClustersResponse.ClusterInfoList[0].CurrentBrokerSoftwareInfo.ConfigurationArn;
const outputMap = await getDependencyStackOutputMap();
log.notice('Removing leftover ENI...');
const describeResponse = await awsRequest('EC2', 'describeNetworkInterfaces', {
Filters: [
{
Name: 'vpc-id',
Values: [outputMap.get('VPC')],
},
{
Name: 'status',
Values: ['available'],
},
],
});
try {
await Promise.all(
describeResponse.NetworkInterfaces.map(networkInterface =>
awsRequest('EC2', 'deleteNetworkInterface', {
NetworkInterfaceId: networkInterface.NetworkInterfaceId,
})
)
);
} catch (e) {
log.error(`Error: ${e} while trying to remove leftover ENIs\n`);
}
log.notice('Removing integration tests CloudFormation stack...');
await awsRequest('CloudFormation', 'deleteStack', {
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
});
await awsRequest('CloudFormation', 'waitFor', 'stackDeleteComplete', {
StackName: SHARED_INFRA_TESTS_CLOUDFORMATION_STACK,
});
log.notice('Removed integration tests CloudFormation stack!');
log.notice('Removing MSK Cluster configuration...');
await awsRequest('Kafka', 'deleteConfiguration', {
Arn: clusterConfArn,
});
log.notice('Removed MSK Cluster configuration');
log.notice('Teardown of integration infrastructure finished');
})();