@geek-fun/serverlessinsight 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/README.md +108 -8
- package/README.zh-CN.md +52 -8
- package/dist/package.json +37 -35
- package/dist/src/commands/deploy.js +17 -7
- package/dist/src/commands/destroy.js +27 -4
- package/dist/src/commands/forceUnlock.js +61 -0
- package/dist/src/commands/index.js +86 -14
- package/dist/src/commands/local.js +10 -1
- package/dist/src/commands/plan.js +33 -0
- package/dist/src/commands/template.js +3 -1
- package/dist/src/commands/validate.js +2 -1
- package/dist/src/common/aliyunClient/apigwOperations.js +652 -0
- package/dist/src/common/aliyunClient/dnsOperations.js +90 -0
- package/dist/src/common/aliyunClient/ecsOperations.js +141 -0
- package/dist/src/common/aliyunClient/esOperations.js +219 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +270 -0
- package/dist/src/common/aliyunClient/index.js +141 -0
- package/dist/src/common/aliyunClient/nasOperations.js +233 -0
- package/dist/src/common/aliyunClient/ossOperations.js +237 -0
- package/dist/src/common/aliyunClient/ramOperations.js +205 -0
- package/dist/src/common/aliyunClient/rdsOperations.js +206 -0
- package/dist/src/common/aliyunClient/slsOperations.js +218 -0
- package/dist/src/common/aliyunClient/tablestoreOperations.js +199 -0
- package/dist/src/common/aliyunClient/types.js +2 -0
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/context.js +32 -14
- package/dist/src/common/credentials.js +39 -0
- package/dist/src/common/dependencyGraph/graph.js +280 -0
- package/dist/src/common/dependencyGraph/index.js +18 -0
- package/dist/src/common/dependencyGraph/types.js +2 -0
- package/dist/src/common/fileUtils.js +16 -0
- package/dist/src/common/hashUtils.js +121 -0
- package/dist/src/common/iacHelper.js +25 -97
- package/dist/src/common/imsClient.js +4 -0
- package/dist/src/common/index.js +7 -2
- package/dist/src/common/lockManager.js +212 -0
- package/dist/src/common/logger.js +89 -6
- package/dist/src/common/providerEnum.js +2 -3
- package/dist/src/common/runtimeMapper.js +160 -0
- package/dist/src/common/scfClient.js +84 -0
- package/dist/src/common/stateManager.js +107 -0
- package/dist/src/common/tencentClient/cosOperations.js +287 -0
- package/dist/src/common/tencentClient/esOperations.js +156 -0
- package/dist/src/common/tencentClient/index.js +116 -0
- package/dist/src/common/tencentClient/scfOperations.js +141 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +211 -0
- package/dist/src/common/tencentClient/types.js +17 -0
- package/dist/src/lang/en.js +254 -0
- package/dist/src/lang/index.js +28 -8
- package/dist/src/lang/zh-CN.js +229 -0
- package/dist/src/parser/bucketParser.js +25 -12
- package/dist/src/parser/databaseParser.js +14 -10
- package/dist/src/parser/functionParser.js +19 -6
- package/dist/src/parser/parseUtils.js +74 -0
- package/dist/src/parser/tableParser.js +19 -17
- package/dist/src/stack/aliyunStack/apigwExecutor.js +84 -0
- package/dist/src/stack/aliyunStack/apigwPlanner.js +118 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +339 -0
- package/dist/src/stack/aliyunStack/apigwTypes.js +125 -0
- package/dist/src/stack/aliyunStack/databaseExecutor.js +112 -0
- package/dist/src/stack/aliyunStack/databasePlanner.js +128 -0
- package/dist/src/stack/aliyunStack/databaseResource.js +228 -0
- package/dist/src/stack/aliyunStack/deployer.js +133 -0
- package/dist/src/stack/aliyunStack/destroyer.js +114 -0
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +141 -0
- package/dist/src/stack/aliyunStack/fc3Executor.js +91 -0
- package/dist/src/stack/aliyunStack/fc3Planner.js +77 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +511 -0
- package/dist/src/stack/aliyunStack/fc3Types.js +76 -0
- package/dist/src/stack/aliyunStack/index.js +40 -0
- package/dist/src/stack/aliyunStack/ossExecutor.js +91 -0
- package/dist/src/stack/aliyunStack/ossPlanner.js +76 -0
- package/dist/src/stack/aliyunStack/ossResource.js +196 -0
- package/dist/src/stack/aliyunStack/ossTypes.js +50 -0
- package/dist/src/stack/aliyunStack/planner.js +37 -0
- package/dist/src/stack/aliyunStack/rdsTypes.js +217 -0
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +92 -0
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +94 -0
- package/dist/src/stack/aliyunStack/tablestoreResource.js +120 -0
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +77 -0
- package/dist/src/stack/bucketTypes.js +17 -0
- package/dist/src/stack/deploy.js +24 -77
- package/dist/src/stack/localStack/bucket.js +11 -6
- package/dist/src/stack/localStack/event.js +10 -5
- package/dist/src/stack/localStack/function.js +13 -7
- package/dist/src/stack/localStack/functionRunner.js +1 -1
- package/dist/src/stack/localStack/localServer.js +7 -6
- package/dist/src/stack/scfStack/cosExecutor.js +91 -0
- package/dist/src/stack/scfStack/cosPlanner.js +76 -0
- package/dist/src/stack/scfStack/cosResource.js +126 -0
- package/dist/src/stack/scfStack/cosTypes.js +46 -0
- package/dist/src/stack/scfStack/deployer.js +91 -0
- package/dist/src/stack/scfStack/destroyer.js +88 -0
- package/dist/src/stack/scfStack/esServerlessExecutor.js +105 -0
- package/dist/src/stack/scfStack/esServerlessPlanner.js +86 -0
- package/dist/src/stack/scfStack/esServerlessResource.js +94 -0
- package/dist/src/stack/scfStack/esServerlessTypes.js +48 -0
- package/dist/src/stack/scfStack/index.js +35 -0
- package/dist/src/stack/scfStack/planner.js +91 -0
- package/dist/src/stack/scfStack/scfExecutor.js +91 -0
- package/dist/src/stack/scfStack/scfPlanner.js +78 -0
- package/dist/src/stack/scfStack/scfResource.js +216 -0
- package/dist/src/stack/scfStack/scfTypes.js +41 -0
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +105 -0
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +90 -0
- package/dist/src/stack/scfStack/tdsqlcResource.js +146 -0
- package/dist/src/stack/scfStack/tdsqlcTypes.js +59 -0
- package/dist/src/types/domains/lock.js +2 -0
- package/dist/src/types/domains/resolvable.js +2 -0
- package/dist/src/types/domains/state.js +19 -0
- package/dist/src/types/index.js +4 -0
- package/dist/src/validator/bucketSchema.js +4 -10
- package/dist/src/validator/databaseSchema.js +36 -36
- package/dist/src/validator/eventSchema.js +3 -2
- package/dist/src/validator/functionSchema.js +51 -46
- package/dist/src/validator/iacSchema.js +52 -3
- package/dist/src/validator/rootSchema.js +47 -1
- package/dist/src/validator/tableschema.js +9 -8
- package/dist/src/validator/templateRefSchema.js +23 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -35
- package/samples/README_TENCENT_COS.md +486 -0
- package/samples/README_TENCENT_SCF.md +272 -0
- package/samples/aliyun-poc-api.yml +1 -1
- package/samples/aliyun-poc-bucket.yml +0 -1
- package/samples/aliyun-poc-domain.yml +0 -1
- package/samples/aliyun-poc-es.yml +14 -13
- package/samples/aliyun-poc-rds.yml +0 -2
- package/samples/aliyun-poc-table.yml +1 -3
- package/samples/tencent-poc-cos.yml +20 -0
- package/samples/tencent-poc-scf.yml +36 -0
- package/dist/src/commands/index.d.ts +0 -2
- package/dist/src/common/index.d.ts +0 -11
- package/dist/src/common/rosAssets.js +0 -178
- package/dist/src/common/rosClient.js +0 -198
- package/dist/src/index.d.ts +0 -1
- package/dist/src/lang/index.d.ts +0 -3
- package/dist/src/parser/index.d.ts +0 -3
- package/dist/src/stack/index.d.ts +0 -1
- package/dist/src/stack/localStack/index.d.ts +0 -5
- package/dist/src/stack/rfsStack/index.d.ts +0 -9
- package/dist/src/stack/rosStack/bootstrap.js +0 -187
- package/dist/src/stack/rosStack/bucket.js +0 -127
- package/dist/src/stack/rosStack/database.js +0 -313
- package/dist/src/stack/rosStack/event.js +0 -143
- package/dist/src/stack/rosStack/function.js +0 -259
- package/dist/src/stack/rosStack/index.d.ts +0 -7
- package/dist/src/stack/rosStack/index.js +0 -75
- package/dist/src/stack/rosStack/stage.js +0 -46
- package/dist/src/stack/rosStack/table.js +0 -95
- package/dist/src/stack/rosStack/tag.js +0 -11
- package/dist/src/stack/rosStack/vars.js +0 -49
- package/dist/src/types/index.d.ts +0 -55
- package/dist/src/types/localStack/index.d.ts +0 -81
- package/dist/src/validator/index.d.ts +0 -1
- package/layers/si-bootstrap-sdk/Dockerfile-aliyuncli +0 -12
- package/layers/si-bootstrap-sdk/README.md +0 -1
- package/layers/si-bootstrap-sdk/package-lock.json +0 -875
- package/layers/si-bootstrap-sdk/package.json +0 -33
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeEsPlan = void 0;
|
|
4
|
+
const esServerlessResource_1 = require("./esServerlessResource");
|
|
5
|
+
const common_1 = require("../../common");
|
|
6
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
+
const lang_1 = require("../../lang");
|
|
8
|
+
const executeCreateAction = async (context, database, currentState) => {
|
|
9
|
+
common_1.logger.info(`Creating Tencent ES serverless space: ${database.name}`);
|
|
10
|
+
const newState = await (0, esServerlessResource_1.createEsResource)(context, database, currentState);
|
|
11
|
+
common_1.logger.info(`Successfully created Tencent ES serverless space: ${database.name}`);
|
|
12
|
+
return newState;
|
|
13
|
+
};
|
|
14
|
+
const executeUpdateAction = async (context, database, spaceId, currentState) => {
|
|
15
|
+
common_1.logger.info(`Updating Tencent ES serverless space: ${database.name}`);
|
|
16
|
+
const newState = await (0, esServerlessResource_1.updateEsResource)(context, database, spaceId, currentState);
|
|
17
|
+
common_1.logger.info(`Successfully updated Tencent ES serverless space: ${database.name}`);
|
|
18
|
+
return newState;
|
|
19
|
+
};
|
|
20
|
+
const executeDeleteAction = async (context, spaceId, logicalId, currentState) => {
|
|
21
|
+
common_1.logger.info(`Deleting Tencent ES serverless space: ${spaceId}`);
|
|
22
|
+
const newState = await (0, esServerlessResource_1.deleteEsResource)(context, spaceId, logicalId, currentState);
|
|
23
|
+
common_1.logger.info(`Successfully deleted Tencent ES serverless space: ${spaceId}`);
|
|
24
|
+
return newState;
|
|
25
|
+
};
|
|
26
|
+
const executeSingleItem = async (context, item, databasesMap, currentState) => {
|
|
27
|
+
if (item.resourceType !== 'TENCENT_ES_SERVERLESS') {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
switch (item.action) {
|
|
31
|
+
case 'noop':
|
|
32
|
+
common_1.logger.info(`No changes for ${item.logicalId}`);
|
|
33
|
+
return null;
|
|
34
|
+
case 'create': {
|
|
35
|
+
const database = databasesMap.get(item.logicalId);
|
|
36
|
+
if (!database) {
|
|
37
|
+
throw new Error(`Database not found for logical ID: ${item.logicalId}`);
|
|
38
|
+
}
|
|
39
|
+
return executeCreateAction(context, database, currentState);
|
|
40
|
+
}
|
|
41
|
+
case 'update': {
|
|
42
|
+
const database = databasesMap.get(item.logicalId);
|
|
43
|
+
if (!database) {
|
|
44
|
+
throw new Error(`Database not found for logical ID: ${item.logicalId}`);
|
|
45
|
+
}
|
|
46
|
+
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
47
|
+
if (!state) {
|
|
48
|
+
throw new Error(`State not found for ${item.logicalId}`);
|
|
49
|
+
}
|
|
50
|
+
const spaceId = state.metadata?.spaceId || state.instances?.[0]?.id;
|
|
51
|
+
if (!spaceId) {
|
|
52
|
+
throw new Error(`Space ID not found in state for ${item.logicalId}`);
|
|
53
|
+
}
|
|
54
|
+
return executeUpdateAction(context, database, spaceId, currentState);
|
|
55
|
+
}
|
|
56
|
+
case 'delete': {
|
|
57
|
+
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
58
|
+
if (!state) {
|
|
59
|
+
common_1.logger.warn(`State not found for ${item.logicalId}, skipping deletion`);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const spaceId = state.metadata?.spaceId || state.instances?.[0]?.id;
|
|
63
|
+
if (!spaceId) {
|
|
64
|
+
throw new Error(`Space ID not found in state for ${item.logicalId}`);
|
|
65
|
+
}
|
|
66
|
+
return executeDeleteAction(context, spaceId, item.logicalId, currentState);
|
|
67
|
+
}
|
|
68
|
+
default:
|
|
69
|
+
common_1.logger.warn(`Unknown action: ${item.action} for ${item.logicalId}`);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const executeEsPlan = async (context, plan, databases, initialState, onStateChange) => {
|
|
74
|
+
const databasesMap = new Map(databases?.map((database) => [`databases.${database.key}`, database]) ?? []);
|
|
75
|
+
const successfulItems = [];
|
|
76
|
+
let currentState = initialState;
|
|
77
|
+
for (const item of plan.items) {
|
|
78
|
+
try {
|
|
79
|
+
const newState = await executeSingleItem(context, item, databasesMap, currentState);
|
|
80
|
+
if (newState !== null) {
|
|
81
|
+
currentState = newState;
|
|
82
|
+
successfulItems.push(item);
|
|
83
|
+
if (onStateChange) {
|
|
84
|
+
onStateChange(currentState);
|
|
85
|
+
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
86
|
+
action: item.action,
|
|
87
|
+
resourceId: item.logicalId,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
state: currentState,
|
|
95
|
+
partialFailure: {
|
|
96
|
+
failedItem: item,
|
|
97
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
98
|
+
successfulItems,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { state: currentState };
|
|
104
|
+
};
|
|
105
|
+
exports.executeEsPlan = executeEsPlan;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateEsPlan = void 0;
|
|
4
|
+
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
|
+
const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
6
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
+
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const planEsDeletion = (logicalId, definition) => ({
|
|
9
|
+
logicalId,
|
|
10
|
+
action: 'delete',
|
|
11
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
12
|
+
changes: { before: definition },
|
|
13
|
+
});
|
|
14
|
+
const generateEsPlan = async (context, state, databases) => {
|
|
15
|
+
const esDatabases = databases?.filter((db) => db.type === "ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */);
|
|
16
|
+
if (!esDatabases || esDatabases.length === 0) {
|
|
17
|
+
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
18
|
+
const items = Object.entries(allStates)
|
|
19
|
+
.filter(([logicalId, resourceState]) => {
|
|
20
|
+
const resourceType = resourceState.metadata?.resourceType;
|
|
21
|
+
return logicalId.startsWith('databases.') && resourceType === 'TENCENT_ES_SERVERLESS';
|
|
22
|
+
})
|
|
23
|
+
.map(([logicalId, resourceState]) => planEsDeletion(logicalId, resourceState.definition));
|
|
24
|
+
return { items };
|
|
25
|
+
}
|
|
26
|
+
const desiredLogicalIds = new Set(esDatabases.map((db) => `databases.${db.key}`));
|
|
27
|
+
const databaseItems = await Promise.all(esDatabases.map(async (database) => {
|
|
28
|
+
const logicalId = `databases.${database.key}`;
|
|
29
|
+
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
30
|
+
const config = (0, esServerlessTypes_1.databaseToTencentEsConfig)(database);
|
|
31
|
+
const desiredDefinition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
|
|
32
|
+
if (!currentState) {
|
|
33
|
+
return {
|
|
34
|
+
logicalId,
|
|
35
|
+
action: 'create',
|
|
36
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
37
|
+
changes: { after: desiredDefinition },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const spaceId = currentState.metadata?.spaceId || currentState.instances?.[0]?.id;
|
|
41
|
+
try {
|
|
42
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
43
|
+
const remoteSpace = spaceId ? await client.es.getSpace(spaceId) : null;
|
|
44
|
+
if (!remoteSpace) {
|
|
45
|
+
return {
|
|
46
|
+
logicalId,
|
|
47
|
+
action: 'create',
|
|
48
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
49
|
+
changes: { before: currentState.definition, after: desiredDefinition },
|
|
50
|
+
drifted: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const currentDefinition = currentState.definition || {};
|
|
54
|
+
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
55
|
+
if (definitionChanged) {
|
|
56
|
+
return {
|
|
57
|
+
logicalId,
|
|
58
|
+
action: 'update',
|
|
59
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
60
|
+
changes: { before: currentDefinition, after: desiredDefinition },
|
|
61
|
+
drifted: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return { logicalId, action: 'noop', resourceType: 'TENCENT_ES_SERVERLESS' };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return {
|
|
68
|
+
logicalId,
|
|
69
|
+
action: 'create',
|
|
70
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
71
|
+
changes: { before: currentState.definition, after: desiredDefinition },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
76
|
+
const deletionItems = Object.entries(allStates)
|
|
77
|
+
.filter(([logicalId, resourceState]) => {
|
|
78
|
+
const resourceType = resourceState.metadata?.resourceType;
|
|
79
|
+
return (logicalId.startsWith('databases.') &&
|
|
80
|
+
!desiredLogicalIds.has(logicalId) &&
|
|
81
|
+
resourceType === 'TENCENT_ES_SERVERLESS');
|
|
82
|
+
})
|
|
83
|
+
.map(([logicalId, resourceState]) => planEsDeletion(logicalId, resourceState.definition));
|
|
84
|
+
return { items: [...databaseItems, ...deletionItems] };
|
|
85
|
+
};
|
|
86
|
+
exports.generateEsPlan = generateEsPlan;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteEsResource = exports.updateEsResource = exports.readEsResource = exports.createEsResource = void 0;
|
|
4
|
+
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
|
+
const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
6
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
+
const buildEsSpaceFromProvider = (info, arn) => {
|
|
8
|
+
return {
|
|
9
|
+
arn,
|
|
10
|
+
id: info.SpaceId,
|
|
11
|
+
spaceId: info.SpaceId,
|
|
12
|
+
spaceName: info.SpaceName,
|
|
13
|
+
status: info.Status,
|
|
14
|
+
createTime: info.CreateTime ?? null,
|
|
15
|
+
indexCount: info.IndexCount ?? null,
|
|
16
|
+
kibanaUrl: info.KibanaUrl ?? null,
|
|
17
|
+
kibanaPrivateUrl: info.KibanaPrivateUrl ?? null,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const createEsResource = async (context, database, state) => {
|
|
21
|
+
const config = (0, esServerlessTypes_1.databaseToTencentEsConfig)(database);
|
|
22
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
23
|
+
const spaceId = await client.es.createSpace({
|
|
24
|
+
SpaceName: config.SpaceName,
|
|
25
|
+
VpcInfo: config.VpcId && config.SubnetId
|
|
26
|
+
? [{ VpcId: config.VpcId, SubnetId: config.SubnetId }]
|
|
27
|
+
: undefined,
|
|
28
|
+
Zone: config.Zone,
|
|
29
|
+
KibanaWhiteIpList: config.KibanaWhiteIpList,
|
|
30
|
+
});
|
|
31
|
+
// Refresh state from provider to get all attributes
|
|
32
|
+
const spaceInfo = await client.es.getSpace(spaceId);
|
|
33
|
+
if (!spaceInfo) {
|
|
34
|
+
throw new Error(`Failed to refresh state for ES space: ${spaceId}`);
|
|
35
|
+
}
|
|
36
|
+
const definition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
|
|
37
|
+
const arn = `arn:tencent:es:${context.region}::space:${spaceId}`;
|
|
38
|
+
const resourceState = {
|
|
39
|
+
mode: 'managed',
|
|
40
|
+
region: context.region,
|
|
41
|
+
definition,
|
|
42
|
+
instances: [buildEsSpaceFromProvider(spaceInfo, arn)],
|
|
43
|
+
lastUpdated: new Date().toISOString(),
|
|
44
|
+
metadata: {
|
|
45
|
+
spaceName: database.name,
|
|
46
|
+
spaceId,
|
|
47
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const logicalId = `databases.${database.key}`;
|
|
51
|
+
return (0, stateManager_1.setResource)(state, logicalId, resourceState);
|
|
52
|
+
};
|
|
53
|
+
exports.createEsResource = createEsResource;
|
|
54
|
+
const readEsResource = async (context, spaceId) => {
|
|
55
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
56
|
+
return await client.es.getSpace(spaceId);
|
|
57
|
+
};
|
|
58
|
+
exports.readEsResource = readEsResource;
|
|
59
|
+
const updateEsResource = async (context, database, spaceId, state) => {
|
|
60
|
+
const config = (0, esServerlessTypes_1.databaseToTencentEsConfig)(database);
|
|
61
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
62
|
+
await client.es.updateSpace(spaceId, {
|
|
63
|
+
SpaceName: config.SpaceName,
|
|
64
|
+
KibanaWhiteIpList: config.KibanaWhiteIpList,
|
|
65
|
+
});
|
|
66
|
+
// Refresh state from provider to get all attributes
|
|
67
|
+
const spaceInfo = await client.es.getSpace(spaceId);
|
|
68
|
+
if (!spaceInfo) {
|
|
69
|
+
throw new Error(`Failed to refresh state for ES space: ${spaceId}`);
|
|
70
|
+
}
|
|
71
|
+
const definition = (0, esServerlessTypes_1.extractTencentEsDefinition)(config);
|
|
72
|
+
const arn = `arn:tencent:es:${context.region}::space:${spaceId}`;
|
|
73
|
+
const resourceState = {
|
|
74
|
+
mode: 'managed',
|
|
75
|
+
region: context.region,
|
|
76
|
+
definition,
|
|
77
|
+
instances: [buildEsSpaceFromProvider(spaceInfo, arn)],
|
|
78
|
+
lastUpdated: new Date().toISOString(),
|
|
79
|
+
metadata: {
|
|
80
|
+
spaceName: database.name,
|
|
81
|
+
spaceId,
|
|
82
|
+
resourceType: 'TENCENT_ES_SERVERLESS',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const logicalId = `databases.${database.key}`;
|
|
86
|
+
return (0, stateManager_1.setResource)(state, logicalId, resourceState);
|
|
87
|
+
};
|
|
88
|
+
exports.updateEsResource = updateEsResource;
|
|
89
|
+
const deleteEsResource = async (context, spaceId, logicalId, state) => {
|
|
90
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
91
|
+
await client.es.deleteSpace(spaceId);
|
|
92
|
+
return (0, stateManager_1.removeResource)(state, logicalId);
|
|
93
|
+
};
|
|
94
|
+
exports.deleteEsResource = deleteEsResource;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractTencentEsDefinition = exports.databaseToTencentEsConfig = void 0;
|
|
4
|
+
// Map database versions to ES versions
|
|
5
|
+
const esVersionMap = new Map([
|
|
6
|
+
[
|
|
7
|
+
`${"ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */}-${"ES_SEARCH_7.10" /* DatabaseVersionEnum['ES_SEARCH_7.10'] */}`,
|
|
8
|
+
{ version: '7.10' },
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
`${"ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */}-${"ES_TIME_SERIES_7.10" /* DatabaseVersionEnum['ES_TIME_SERIES_7.10'] */}`,
|
|
12
|
+
{ version: '7.10' },
|
|
13
|
+
],
|
|
14
|
+
]);
|
|
15
|
+
const databaseToTencentEsConfig = (database) => {
|
|
16
|
+
const engineConfig = esVersionMap.get(`${database.type}-${database.version}`);
|
|
17
|
+
if (!engineConfig) {
|
|
18
|
+
throw new Error(`Unsupported ES database type/version: ${database.type}-${database.version}`);
|
|
19
|
+
}
|
|
20
|
+
const config = {
|
|
21
|
+
SpaceName: database.name,
|
|
22
|
+
Version: engineConfig.version,
|
|
23
|
+
};
|
|
24
|
+
// Add network configuration
|
|
25
|
+
if (database.network.vpcId) {
|
|
26
|
+
config.VpcId = database.network.vpcId;
|
|
27
|
+
}
|
|
28
|
+
if (database.network.subnetId) {
|
|
29
|
+
config.SubnetId = database.network.subnetId;
|
|
30
|
+
}
|
|
31
|
+
// Add IP whitelist from ingress rules for public access
|
|
32
|
+
if (database.network.ingressRules && database.network.ingressRules.length > 0) {
|
|
33
|
+
config.KibanaWhiteIpList = database.network.ingressRules;
|
|
34
|
+
}
|
|
35
|
+
return config;
|
|
36
|
+
};
|
|
37
|
+
exports.databaseToTencentEsConfig = databaseToTencentEsConfig;
|
|
38
|
+
const extractTencentEsDefinition = (config) => {
|
|
39
|
+
return {
|
|
40
|
+
spaceName: config.SpaceName,
|
|
41
|
+
version: config.Version ?? null,
|
|
42
|
+
vpcId: config.VpcId ?? null,
|
|
43
|
+
subnetId: config.SubnetId ?? null,
|
|
44
|
+
zone: config.Zone ?? null,
|
|
45
|
+
kibanaWhiteIpList: config.KibanaWhiteIpList ?? null,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.extractTencentEsDefinition = extractTencentEsDefinition;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./scfTypes"), exports);
|
|
18
|
+
__exportStar(require("./scfResource"), exports);
|
|
19
|
+
__exportStar(require("./scfPlanner"), exports);
|
|
20
|
+
__exportStar(require("./scfExecutor"), exports);
|
|
21
|
+
__exportStar(require("./cosTypes"), exports);
|
|
22
|
+
__exportStar(require("./cosResource"), exports);
|
|
23
|
+
__exportStar(require("./cosPlanner"), exports);
|
|
24
|
+
__exportStar(require("./cosExecutor"), exports);
|
|
25
|
+
__exportStar(require("./tdsqlcTypes"), exports);
|
|
26
|
+
__exportStar(require("./tdsqlcResource"), exports);
|
|
27
|
+
__exportStar(require("./tdsqlcPlanner"), exports);
|
|
28
|
+
__exportStar(require("./tdsqlcExecutor"), exports);
|
|
29
|
+
__exportStar(require("./esServerlessTypes"), exports);
|
|
30
|
+
__exportStar(require("./esServerlessResource"), exports);
|
|
31
|
+
__exportStar(require("./esServerlessPlanner"), exports);
|
|
32
|
+
__exportStar(require("./esServerlessExecutor"), exports);
|
|
33
|
+
__exportStar(require("./deployer"), exports);
|
|
34
|
+
__exportStar(require("./destroyer"), exports);
|
|
35
|
+
__exportStar(require("./planner"), exports);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.displayPlan = exports.generateTencentPlan = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
6
|
+
const scfPlanner_1 = require("./scfPlanner");
|
|
7
|
+
const cosPlanner_1 = require("./cosPlanner");
|
|
8
|
+
const tdsqlcPlanner_1 = require("./tdsqlcPlanner");
|
|
9
|
+
const esServerlessPlanner_1 = require("./esServerlessPlanner");
|
|
10
|
+
const generateTencentPlan = async (iac) => {
|
|
11
|
+
const context = (0, common_1.getContext)();
|
|
12
|
+
const state = (0, common_1.loadState)(iac.provider.name, process.cwd());
|
|
13
|
+
const functionPlan = await (0, scfPlanner_1.generateFunctionPlan)(context, state, iac.functions);
|
|
14
|
+
const bucketPlan = await (0, cosPlanner_1.generateBucketPlan)(context, state, iac.buckets);
|
|
15
|
+
const databasePlan = await (0, tdsqlcPlanner_1.generateDatabasePlan)(context, state, iac.databases);
|
|
16
|
+
const esPlan = await (0, esServerlessPlanner_1.generateEsPlan)(context, state, iac.databases);
|
|
17
|
+
const allItems = [
|
|
18
|
+
...functionPlan.items,
|
|
19
|
+
...bucketPlan.items,
|
|
20
|
+
...databasePlan.items,
|
|
21
|
+
...esPlan.items,
|
|
22
|
+
];
|
|
23
|
+
const dependencyInfo = (0, common_1.getDependencyInfo)(allItems);
|
|
24
|
+
if (dependencyInfo.cycleError) {
|
|
25
|
+
throw new Error(`${lang_1.lang.__('CYCLE_DETECTED')}: ${dependencyInfo.cycleError.cycle.join(' -> ')}`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
items: dependencyInfo.order,
|
|
29
|
+
levels: dependencyInfo.levels,
|
|
30
|
+
graph: dependencyInfo.graph,
|
|
31
|
+
dotGraph: (0, common_1.toDotFormat)(dependencyInfo.graph),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.generateTencentPlan = generateTencentPlan;
|
|
35
|
+
const displayPlan = (planResult) => {
|
|
36
|
+
const separator = '========================================';
|
|
37
|
+
if (planResult.items.length === 0) {
|
|
38
|
+
common_1.logger.info(`${separator}\n${lang_1.lang.__('DEPLOYMENT_PLAN')}\n${separator}\n${lang_1.lang.__('NO_CHANGES_INFRASTRUCTURE_UP_TO_DATE')}`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const createActions = planResult.items.filter((item) => item.action === 'create');
|
|
42
|
+
const updateActions = planResult.items.filter((item) => item.action === 'update');
|
|
43
|
+
const deleteActions = planResult.items.filter((item) => item.action === 'delete');
|
|
44
|
+
const noopActions = planResult.items.filter((item) => item.action === 'noop');
|
|
45
|
+
const sections = [];
|
|
46
|
+
if (createActions.length > 0) {
|
|
47
|
+
const createLines = [`[${lang_1.lang.__('CREATE')}]:`];
|
|
48
|
+
for (const item of createActions) {
|
|
49
|
+
createLines.push(` + ${item.logicalId} (${item.resourceType})`);
|
|
50
|
+
if (item.changes?.after) {
|
|
51
|
+
const jsonStr = JSON.stringify(item.changes.after, null, 2);
|
|
52
|
+
createLines.push(` ${jsonStr.split('\n').join('\n ')}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sections.push(createLines.join('\n'));
|
|
56
|
+
}
|
|
57
|
+
if (updateActions.length > 0) {
|
|
58
|
+
const updateLines = [`[${lang_1.lang.__('UPDATE')}]:`];
|
|
59
|
+
for (const item of updateActions) {
|
|
60
|
+
updateLines.push(` ~ ${item.logicalId} (${item.resourceType})`);
|
|
61
|
+
if (item.drifted) {
|
|
62
|
+
updateLines.push(` [${lang_1.lang.__('DRIFTED')}] ${lang_1.lang.__('REMOTE_CONFIG_DIFFERS')}`);
|
|
63
|
+
}
|
|
64
|
+
if (item.changes) {
|
|
65
|
+
const jsonStr = JSON.stringify(item.changes, null, 2);
|
|
66
|
+
updateLines.push(` ${lang_1.lang.__('CHANGES')}: ${jsonStr.split('\n').join('\n ')}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
sections.push(updateLines.join('\n'));
|
|
70
|
+
}
|
|
71
|
+
if (deleteActions.length > 0) {
|
|
72
|
+
const deleteLines = [`[${lang_1.lang.__('DELETE')}]:`];
|
|
73
|
+
for (const item of deleteActions) {
|
|
74
|
+
deleteLines.push(` - ${item.logicalId} (${item.resourceType})`);
|
|
75
|
+
if (item.changes?.before) {
|
|
76
|
+
const jsonStr = JSON.stringify(item.changes.before, null, 2);
|
|
77
|
+
deleteLines.push(` ${jsonStr.split('\n').join('\n ')}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
sections.push(deleteLines.join('\n'));
|
|
81
|
+
}
|
|
82
|
+
if (noopActions.length > 0) {
|
|
83
|
+
const noopLines = [`[${lang_1.lang.__('NO_CHANGE')}]:`];
|
|
84
|
+
for (const item of noopActions) {
|
|
85
|
+
noopLines.push(` = ${item.logicalId} (${item.resourceType})`);
|
|
86
|
+
}
|
|
87
|
+
sections.push(noopLines.join('\n'));
|
|
88
|
+
}
|
|
89
|
+
common_1.logger.info(`\n${separator}\n${lang_1.lang.__('DEPLOYMENT_PLAN')}\n${separator}\n${sections.join('\n\n')}\n\n${separator}\n${lang_1.lang.__('PLAN')}: ${createActions.length} ${lang_1.lang.__('TO_CREATE')}, ${updateActions.length} ${lang_1.lang.__('TO_UPDATE')}, ${deleteActions.length} ${lang_1.lang.__('TO_DELETE')}, ${noopActions.length} ${lang_1.lang.__('UNCHANGED')}\n${separator}`);
|
|
90
|
+
};
|
|
91
|
+
exports.displayPlan = displayPlan;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeFunctionPlan = void 0;
|
|
4
|
+
const scfResource_1 = require("./scfResource");
|
|
5
|
+
const common_1 = require("../../common");
|
|
6
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
+
const lang_1 = require("../../lang");
|
|
8
|
+
const executeCreateAction = async (context, fn, currentState) => {
|
|
9
|
+
common_1.logger.info(`Creating function: ${fn.name}`);
|
|
10
|
+
const newState = await (0, scfResource_1.createResource)(context, fn, currentState);
|
|
11
|
+
common_1.logger.info(`Successfully created function: ${fn.name}`);
|
|
12
|
+
return newState;
|
|
13
|
+
};
|
|
14
|
+
const executeUpdateAction = async (context, fn, currentState) => {
|
|
15
|
+
common_1.logger.info(`Updating function: ${fn.name}`);
|
|
16
|
+
const newState = await (0, scfResource_1.updateResource)(context, fn, currentState);
|
|
17
|
+
common_1.logger.info(`Successfully updated function: ${fn.name}`);
|
|
18
|
+
return newState;
|
|
19
|
+
};
|
|
20
|
+
const executeDeleteAction = async (context, functionName, logicalId, currentState) => {
|
|
21
|
+
common_1.logger.info(`Deleting function: ${functionName}`);
|
|
22
|
+
const newState = await (0, scfResource_1.deleteResource)(context, functionName, logicalId, currentState);
|
|
23
|
+
common_1.logger.info(`Successfully deleted function: ${functionName}`);
|
|
24
|
+
return newState;
|
|
25
|
+
};
|
|
26
|
+
const executeSingleItem = async (context, item, functionsMap, currentState) => {
|
|
27
|
+
switch (item.action) {
|
|
28
|
+
case 'noop':
|
|
29
|
+
common_1.logger.info(`No changes for ${item.logicalId}`);
|
|
30
|
+
return null;
|
|
31
|
+
case 'create': {
|
|
32
|
+
const fn = functionsMap.get(item.logicalId);
|
|
33
|
+
if (!fn) {
|
|
34
|
+
throw new Error(`Function not found for logical ID: ${item.logicalId}`);
|
|
35
|
+
}
|
|
36
|
+
return executeCreateAction(context, fn, currentState);
|
|
37
|
+
}
|
|
38
|
+
case 'update': {
|
|
39
|
+
const fn = functionsMap.get(item.logicalId);
|
|
40
|
+
if (!fn) {
|
|
41
|
+
throw new Error(`Function not found for logical ID: ${item.logicalId}`);
|
|
42
|
+
}
|
|
43
|
+
return executeUpdateAction(context, fn, currentState);
|
|
44
|
+
}
|
|
45
|
+
case 'delete': {
|
|
46
|
+
const state = (0, stateManager_1.getResource)(currentState, item.logicalId);
|
|
47
|
+
if (!state) {
|
|
48
|
+
common_1.logger.warn(`State not found for ${item.logicalId}, skipping deletion`);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const functionName = state.definition.functionName;
|
|
52
|
+
return executeDeleteAction(context, functionName, item.logicalId, currentState);
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
common_1.logger.warn(`Unknown action: ${item.action} for ${item.logicalId}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const executeFunctionPlan = async (context, plan, functions, initialState, onStateChange) => {
|
|
60
|
+
const functionsMap = new Map(functions?.map((fn) => [`functions.${fn.key}`, fn]) ?? []);
|
|
61
|
+
const successfulItems = [];
|
|
62
|
+
let currentState = initialState;
|
|
63
|
+
for (const item of plan.items) {
|
|
64
|
+
try {
|
|
65
|
+
const newState = await executeSingleItem(context, item, functionsMap, currentState);
|
|
66
|
+
if (newState !== null) {
|
|
67
|
+
currentState = newState;
|
|
68
|
+
successfulItems.push(item);
|
|
69
|
+
if (onStateChange) {
|
|
70
|
+
onStateChange(currentState);
|
|
71
|
+
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
72
|
+
action: item.action,
|
|
73
|
+
resourceId: item.logicalId,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
state: currentState,
|
|
81
|
+
partialFailure: {
|
|
82
|
+
failedItem: item,
|
|
83
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
84
|
+
successfulItems,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { state: currentState };
|
|
90
|
+
};
|
|
91
|
+
exports.executeFunctionPlan = executeFunctionPlan;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateFunctionPlan = void 0;
|
|
4
|
+
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
|
+
const scfTypes_1 = require("./scfTypes");
|
|
6
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
7
|
+
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const planFunctionDeletion = (logicalId, definition) => ({
|
|
9
|
+
logicalId,
|
|
10
|
+
action: 'delete',
|
|
11
|
+
resourceType: 'SCF',
|
|
12
|
+
changes: { before: definition },
|
|
13
|
+
});
|
|
14
|
+
const generateFunctionPlan = async (context, state, functions) => {
|
|
15
|
+
if (!functions || functions.length === 0) {
|
|
16
|
+
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
17
|
+
const items = Object.entries(allStates)
|
|
18
|
+
.filter(([logicalId]) => logicalId.startsWith('functions.'))
|
|
19
|
+
.map(([logicalId, resourceState]) => planFunctionDeletion(logicalId, resourceState.definition));
|
|
20
|
+
return { items };
|
|
21
|
+
}
|
|
22
|
+
const desiredLogicalIds = new Set(functions.map((fn) => `functions.${fn.key}`));
|
|
23
|
+
const functionItems = await Promise.all(functions.map(async (fn) => {
|
|
24
|
+
const logicalId = `functions.${fn.key}`;
|
|
25
|
+
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
26
|
+
const config = (0, scfTypes_1.functionToScfConfig)(fn);
|
|
27
|
+
const codePath = fn.code.path;
|
|
28
|
+
const desiredCodeHash = (0, hashUtils_1.computeFileHash)(codePath);
|
|
29
|
+
const desiredDefinition = (0, scfTypes_1.extractScfDefinition)(config, desiredCodeHash);
|
|
30
|
+
if (!currentState) {
|
|
31
|
+
return {
|
|
32
|
+
logicalId,
|
|
33
|
+
action: 'create',
|
|
34
|
+
resourceType: 'SCF',
|
|
35
|
+
changes: { after: desiredDefinition },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
40
|
+
const remoteFunction = await client.scf.getFunction(fn.name);
|
|
41
|
+
if (!remoteFunction) {
|
|
42
|
+
return {
|
|
43
|
+
logicalId,
|
|
44
|
+
action: 'create',
|
|
45
|
+
resourceType: 'SCF',
|
|
46
|
+
changes: { before: currentState.definition, after: desiredDefinition },
|
|
47
|
+
drifted: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const currentDefinition = currentState.definition || {};
|
|
51
|
+
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
52
|
+
if (definitionChanged) {
|
|
53
|
+
return {
|
|
54
|
+
logicalId,
|
|
55
|
+
action: 'update',
|
|
56
|
+
resourceType: 'SCF',
|
|
57
|
+
changes: { before: currentDefinition, after: desiredDefinition },
|
|
58
|
+
drifted: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return { logicalId, action: 'noop', resourceType: 'SCF' };
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return {
|
|
65
|
+
logicalId,
|
|
66
|
+
action: 'create',
|
|
67
|
+
resourceType: 'SCF',
|
|
68
|
+
changes: { before: currentState.definition, after: desiredDefinition },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
73
|
+
const deletionItems = Object.entries(allStates)
|
|
74
|
+
.filter(([logicalId]) => logicalId.startsWith('functions.') && !desiredLogicalIds.has(logicalId))
|
|
75
|
+
.map(([logicalId, resourceState]) => planFunctionDeletion(logicalId, resourceState.definition));
|
|
76
|
+
return { items: [...functionItems, ...deletionItems] };
|
|
77
|
+
};
|
|
78
|
+
exports.generateFunctionPlan = generateFunctionPlan;
|