@geek-fun/serverlessinsight 0.8.9 → 0.9.1
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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +123 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +93 -0
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +148 -0
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/CHANGELOG.md +29 -0
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/package.json +2 -2
- package/dist/src/commands/deploy.js +12 -4
- package/dist/src/commands/destroy.js +8 -2
- package/dist/src/commands/forceUnlock.js +5 -5
- package/dist/src/commands/index.js +114 -53
- package/dist/src/commands/login.js +12 -1
- package/dist/src/commands/migrate.js +287 -0
- package/dist/src/commands/plan.js +7 -1
- package/dist/src/commands/show.js +37 -25
- package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
- package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
- package/dist/src/common/aliyunClient/fc3Operations.js +12 -3
- package/dist/src/common/aliyunClient/nasOperations.js +4 -3
- package/dist/src/common/aliyunClient/ossOperations.js +52 -8
- package/dist/src/common/aliyunClient/slsOperations.js +3 -2
- package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
- package/dist/src/common/apiClient.js +22 -5
- package/dist/src/common/context.js +5 -4
- package/dist/src/common/lockManager.js +1 -1
- package/dist/src/common/migrationMarker.js +34 -0
- package/dist/src/common/nameBuilder.js +13 -1
- package/dist/src/common/planCompare.js +31 -1
- package/dist/src/common/planFormatter.js +69 -54
- package/dist/src/common/refreshPlanner.js +31 -8
- package/dist/src/common/runtimeMapper.js +7 -3
- package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
- package/dist/src/common/stateBackend/index.js +5 -2
- package/dist/src/common/stateBackend/localStateBackend.js +8 -2
- package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
- package/dist/src/common/stateBackend/saasStateBackend.js +83 -5
- package/dist/src/common/stateManager.js +56 -5
- package/dist/src/common/tencentClient/cosOperations.js +1 -1
- package/dist/src/common/tencentClient/scfOperations.js +2 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
- package/dist/src/common/volcengineClient/index.js +6 -2
- package/dist/src/common/volcengineClient/vefaasOperations.js +3 -3
- package/dist/src/lang/en.js +231 -7
- package/dist/src/lang/zh-CN.js +230 -7
- package/dist/src/parser/index.js +1 -1
- package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/apigwPlanner.js +26 -5
- package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
- package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
- package/dist/src/stack/aliyunStack/databasePlanner.js +8 -3
- package/dist/src/stack/aliyunStack/databaseResource.js +28 -12
- package/dist/src/stack/aliyunStack/deployer.js +30 -13
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +46 -25
- package/dist/src/stack/aliyunStack/fc3Resource.js +80 -31
- package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/ossPlanner.js +6 -1
- package/dist/src/stack/aliyunStack/ossResource.js +14 -3
- package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +2 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +5 -4
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
- package/dist/src/stack/deploy.js +12 -7
- package/dist/src/stack/localStack/functionRunner.js +5 -4
- package/dist/src/stack/scfStack/cosExecutor.js +2 -2
- package/dist/src/stack/scfStack/cosPlanner.js +6 -1
- package/dist/src/stack/scfStack/cosResource.js +8 -4
- package/dist/src/stack/scfStack/deployer.js +21 -6
- package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
- package/dist/src/stack/scfStack/esServerlessPlanner.js +6 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +12 -4
- package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
- package/dist/src/stack/scfStack/scfExecutor.js +2 -2
- package/dist/src/stack/scfStack/scfPlanner.js +26 -27
- package/dist/src/stack/scfStack/scfResource.js +38 -13
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +6 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +12 -4
- package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/apigwPlanner.js +5 -1
- package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
- package/dist/src/stack/volcengineStack/deployer.js +15 -4
- package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +6 -1
- package/dist/src/stack/volcengineStack/tosResource.js +11 -4
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +39 -11
- package/dist/src/stack/volcengineStack/vefaasResource.js +11 -3
- package/dist/src/validator/rootSchema.js +29 -2
- package/dist/src/validator/semanticValidation.js +24 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -148,7 +148,7 @@ const createDatabaseResource = async (context, database, state) => {
|
|
|
148
148
|
"RDS_MSSQL_SERVERLESS" /* DatabaseEnum.RDS_MSSQL_SERVERLESS */,
|
|
149
149
|
].includes(database.type);
|
|
150
150
|
if (!isEs && !isRds) {
|
|
151
|
-
throw new Error(
|
|
151
|
+
throw new Error(lang_1.lang.__('DATABASE_TYPE_UNSUPPORTED', { type: database.type }));
|
|
152
152
|
}
|
|
153
153
|
const resourceType = isEs ? 'ALIYUN_ES_SERVERLESS' : 'ALIYUN_RDS_SERVERLESS';
|
|
154
154
|
const definition = isEs
|
|
@@ -181,10 +181,18 @@ const createDatabaseResource = async (context, database, state) => {
|
|
|
181
181
|
const probe = await client.es.getApp(config.appName);
|
|
182
182
|
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(probe.tags))) {
|
|
183
183
|
instanceId = probe.appId ?? config.appName;
|
|
184
|
-
logger_1.logger.info(
|
|
184
|
+
logger_1.logger.info(lang_1.lang.__('RESOURCE_OWNERSHIP_TAG_ADOPT', {
|
|
185
|
+
resourceType: 'ES app',
|
|
186
|
+
name: config.appName,
|
|
187
|
+
tag: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
188
|
+
}));
|
|
185
189
|
}
|
|
186
190
|
else {
|
|
187
|
-
throw new Error(
|
|
191
|
+
throw new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
192
|
+
resourceType: 'ES app',
|
|
193
|
+
resourceName: config.appName,
|
|
194
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
195
|
+
}), { cause: error });
|
|
188
196
|
}
|
|
189
197
|
}
|
|
190
198
|
else {
|
|
@@ -194,7 +202,7 @@ const createDatabaseResource = async (context, database, state) => {
|
|
|
194
202
|
// Refresh state from provider to get all attributes
|
|
195
203
|
const appInfo = await client.es.getApp(instanceId);
|
|
196
204
|
if (!appInfo) {
|
|
197
|
-
throw new Error(
|
|
205
|
+
throw new Error(lang_1.lang.__('REFRESH_STATE_ES_APP', { appId: instanceId }));
|
|
198
206
|
}
|
|
199
207
|
const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
|
|
200
208
|
instance = buildEsInstanceFromProvider(appInfo, sid);
|
|
@@ -211,10 +219,18 @@ const createDatabaseResource = async (context, database, state) => {
|
|
|
211
219
|
if (probe?.dbInstanceId &&
|
|
212
220
|
(0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(probe.tags))) {
|
|
213
221
|
instanceId = probe.dbInstanceId;
|
|
214
|
-
logger_1.logger.info(
|
|
222
|
+
logger_1.logger.info(lang_1.lang.__('RESOURCE_OWNERSHIP_TAG_ADOPT', {
|
|
223
|
+
resourceType: 'RDS instance',
|
|
224
|
+
name: config.dbInstanceDescription,
|
|
225
|
+
tag: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
226
|
+
}));
|
|
215
227
|
}
|
|
216
228
|
else {
|
|
217
|
-
throw new Error(
|
|
229
|
+
throw new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
230
|
+
resourceType: 'RDS instance',
|
|
231
|
+
resourceName: config.dbInstanceDescription,
|
|
232
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
233
|
+
}), { cause: error });
|
|
218
234
|
}
|
|
219
235
|
}
|
|
220
236
|
else {
|
|
@@ -224,7 +240,7 @@ const createDatabaseResource = async (context, database, state) => {
|
|
|
224
240
|
// Refresh state from provider to get all attributes
|
|
225
241
|
const rdsInfo = await client.rds.getInstance(instanceId);
|
|
226
242
|
if (!rdsInfo) {
|
|
227
|
-
throw new Error(
|
|
243
|
+
throw new Error(lang_1.lang.__('REFRESH_STATE_RDS_INSTANCE', { instanceId }));
|
|
228
244
|
}
|
|
229
245
|
const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
|
|
230
246
|
instance = buildRdsInstanceFromProvider(rdsInfo, sid);
|
|
@@ -257,7 +273,7 @@ const readDatabaseResource = async (context, instanceId, resourceType) => {
|
|
|
257
273
|
else if (resourceType === 'ALIYUN_RDS_SERVERLESS') {
|
|
258
274
|
return await client.rds.getInstance(instanceId);
|
|
259
275
|
}
|
|
260
|
-
throw new Error(
|
|
276
|
+
throw new Error(lang_1.lang.__('RESOURCE_TYPE_UNSUPPORTED', { type: resourceType }));
|
|
261
277
|
};
|
|
262
278
|
exports.readDatabaseResource = readDatabaseResource;
|
|
263
279
|
const updateDatabaseResource = async (context, database, instanceId, resourceType, state) => {
|
|
@@ -270,7 +286,7 @@ const updateDatabaseResource = async (context, database, instanceId, resourceTyp
|
|
|
270
286
|
// Refresh state from provider to get all attributes
|
|
271
287
|
const appInfo = await client.es.getApp(instanceId);
|
|
272
288
|
if (!appInfo) {
|
|
273
|
-
throw new Error(
|
|
289
|
+
throw new Error(lang_1.lang.__('REFRESH_STATE_ES_APP', { appId: instanceId }));
|
|
274
290
|
}
|
|
275
291
|
definition = (0, esServerlessTypes_1.extractEsDefinition)(config);
|
|
276
292
|
const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
|
|
@@ -282,14 +298,14 @@ const updateDatabaseResource = async (context, database, instanceId, resourceTyp
|
|
|
282
298
|
// Refresh state from provider to get all attributes
|
|
283
299
|
const rdsInfo = await client.rds.getInstance(instanceId);
|
|
284
300
|
if (!rdsInfo) {
|
|
285
|
-
throw new Error(
|
|
301
|
+
throw new Error(lang_1.lang.__('REFRESH_STATE_RDS_INSTANCE', { instanceId }));
|
|
286
302
|
}
|
|
287
303
|
definition = (0, rdsTypes_1.extractRdsDefinition)(config);
|
|
288
304
|
const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
|
|
289
305
|
instance = buildRdsInstanceFromProvider(rdsInfo, sid);
|
|
290
306
|
}
|
|
291
307
|
else {
|
|
292
|
-
throw new Error(
|
|
308
|
+
throw new Error(lang_1.lang.__('RESOURCE_TYPE_UNSUPPORTED', { type: resourceType }));
|
|
293
309
|
}
|
|
294
310
|
const resourceState = {
|
|
295
311
|
mode: 'managed',
|
|
@@ -318,7 +334,7 @@ const deleteDatabaseResource = async (context, instanceId, resourceType, logical
|
|
|
318
334
|
await client.rds.deleteInstance(instanceId);
|
|
319
335
|
}
|
|
320
336
|
else {
|
|
321
|
-
throw new Error(
|
|
337
|
+
throw new Error(lang_1.lang.__('RESOURCE_TYPE_UNSUPPORTED', { type: resourceType }));
|
|
322
338
|
}
|
|
323
339
|
}
|
|
324
340
|
catch (err) {
|
|
@@ -73,7 +73,12 @@ const buildRoleArnResolver = (state, functions) => {
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
exports.buildRoleArnResolver = buildRoleArnResolver;
|
|
76
|
-
|
|
76
|
+
// Issue #246: when the approved plan is passed through, the executor runs
|
|
77
|
+
// exactly the displayed items — partitioned by resourceType, no re-probe.
|
|
78
|
+
const partitionPlan = (plan, types) => ({
|
|
79
|
+
items: plan.items.filter((item) => types.includes(item.resourceType)),
|
|
80
|
+
});
|
|
81
|
+
const deployAliyunStack = async (iac, backend, approvedPlan) => {
|
|
77
82
|
const context = (0, common_1.getContext)();
|
|
78
83
|
// Cache IAC for access throughout the deployment
|
|
79
84
|
(0, common_1.setIac)(iac);
|
|
@@ -81,18 +86,30 @@ const deployAliyunStack = async (iac, backend) => {
|
|
|
81
86
|
let state = await backend.loadState(iac.provider.name, iac.app, iac.service, context.stage);
|
|
82
87
|
const onStateChange = createSaveStateFn(backend, iac, context.stage);
|
|
83
88
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN'));
|
|
84
|
-
const functionPlan =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
const functionPlan = approvedPlan
|
|
90
|
+
? partitionPlan(approvedPlan, ['ALIYUN_FC3'])
|
|
91
|
+
: await (0, fc3Planner_1.generateFunctionPlan)(context, state, iac.functions);
|
|
92
|
+
const bucketPlan = approvedPlan
|
|
93
|
+
? partitionPlan(approvedPlan, ['ALIYUN_OSS_BUCKET'])
|
|
94
|
+
: await (0, ossPlanner_1.generateBucketPlan)(context, state, iac.buckets);
|
|
95
|
+
const databasePlan = approvedPlan
|
|
96
|
+
? partitionPlan(approvedPlan, ['ALIYUN_RDS_SERVERLESS', 'ALIYUN_ES_SERVERLESS'])
|
|
97
|
+
: await (0, databasePlanner_1.generateDatabasePlan)(context, state, iac.databases);
|
|
98
|
+
const tablePlan = approvedPlan
|
|
99
|
+
? partitionPlan(approvedPlan, ['ALIYUN_TABLESTORE_TABLE'])
|
|
100
|
+
: await (0, tablestorePlanner_1.generateTablePlan)(context, state, iac.tables);
|
|
101
|
+
const eventPlan = approvedPlan
|
|
102
|
+
? partitionPlan(approvedPlan, ['ALIYUN_APIGW'])
|
|
103
|
+
: await (0, apigwPlanner_1.generateApigwPlan)(context, state, iac.events, iac.service);
|
|
104
|
+
const allItems = approvedPlan
|
|
105
|
+
? [...approvedPlan.items]
|
|
106
|
+
: [
|
|
107
|
+
...functionPlan.items,
|
|
108
|
+
...bucketPlan.items,
|
|
109
|
+
...databasePlan.items,
|
|
110
|
+
...tablePlan.items,
|
|
111
|
+
...eventPlan.items,
|
|
112
|
+
];
|
|
96
113
|
// Build dependency graph for validation (e.g. cycle detection) and logging
|
|
97
114
|
const dependencyInfo = (0, common_1.getDependencyInfo)(allItems);
|
|
98
115
|
if (dependencyInfo.cycleError) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cloudEsToDefinition = exports.extractEsDefinition = exports.databaseToEsConfig = void 0;
|
|
4
|
+
const lang_1 = require("../../lang");
|
|
4
5
|
// Map database versions to ES versions
|
|
5
6
|
const esVersionMap = new Map([
|
|
6
7
|
[
|
|
@@ -23,7 +24,7 @@ const esVersionMap = new Map([
|
|
|
23
24
|
const databaseToEsConfig = (database) => {
|
|
24
25
|
const engineConfig = esVersionMap.get(`${database.type}-${database.version}`);
|
|
25
26
|
if (!engineConfig) {
|
|
26
|
-
throw new Error(
|
|
27
|
+
throw new Error(lang_1.lang.__('ES_DB_TYPE_VERSION_UNSUPPORTED', { type: database.type, version: database.version }));
|
|
27
28
|
}
|
|
28
29
|
const { version, category } = engineConfig;
|
|
29
30
|
const config = {
|
|
@@ -35,14 +35,14 @@ const executeSingleItem = async (context, item, functionsMap, currentState) => {
|
|
|
35
35
|
case 'create': {
|
|
36
36
|
const fn = functionsMap.get(item.logicalId);
|
|
37
37
|
if (!fn) {
|
|
38
|
-
throw new Error(
|
|
38
|
+
throw new Error(lang_1.lang.__('RESOURCE_FUNCTION_NOT_FOUND', { logicalId: item.logicalId }));
|
|
39
39
|
}
|
|
40
40
|
return executeCreateAction(context, fn, currentState);
|
|
41
41
|
}
|
|
42
42
|
case 'update': {
|
|
43
43
|
const fn = functionsMap.get(item.logicalId);
|
|
44
44
|
if (!fn) {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error(lang_1.lang.__('RESOURCE_FUNCTION_NOT_FOUND', { logicalId: item.logicalId }));
|
|
46
46
|
}
|
|
47
47
|
return executeUpdateAction(context, fn, currentState, item.drifted);
|
|
48
48
|
}
|
|
@@ -124,19 +124,21 @@ const parseRolePolicyDocument = (raw) => {
|
|
|
124
124
|
* - logConfig must be derivable from state: with logging on but no recorded
|
|
125
125
|
* logstore instance the executor creates one during update and derives the
|
|
126
126
|
* grant from that new logstore, which the planner cannot know → skip.
|
|
127
|
+
* Returns an i18n drift-reason key (issue #246) instead of a boolean so the
|
|
128
|
+
* plan can say WHICH dimension drifted; null means no drift.
|
|
127
129
|
*/
|
|
128
130
|
const detectRolePolicyDrift = async (context, state, fn, currentState, roleName, cloudRole) => {
|
|
129
131
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
130
132
|
const logicalId = `functions.${fn.key}`;
|
|
131
133
|
const iamRole = fn.iam?.role;
|
|
132
134
|
if (!iamRole || typeof iamRole === 'string') {
|
|
133
|
-
return
|
|
135
|
+
return null;
|
|
134
136
|
}
|
|
135
137
|
const roleInstance = currentState.instances?.find((i) => i.type === 'ALIYUN_RAM_ROLE' &&
|
|
136
138
|
i.id === roleName &&
|
|
137
139
|
!i.external);
|
|
138
140
|
if (!roleInstance) {
|
|
139
|
-
return
|
|
141
|
+
return null;
|
|
140
142
|
}
|
|
141
143
|
// Conservative ownership scan (mirrors collectRolePeers semantics without
|
|
142
144
|
// requiring context.iac): any OTHER function in state recording the same
|
|
@@ -147,13 +149,13 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
147
149
|
i.id === roleName &&
|
|
148
150
|
!i.external));
|
|
149
151
|
if (sharedRole) {
|
|
150
|
-
return
|
|
152
|
+
return null;
|
|
151
153
|
}
|
|
152
154
|
let logConfig;
|
|
153
155
|
if (fn.log) {
|
|
154
156
|
const logstoreInstance = currentState.instances?.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
155
157
|
if (!logstoreInstance?.id) {
|
|
156
|
-
return
|
|
158
|
+
return null;
|
|
157
159
|
}
|
|
158
160
|
const [project, logstore] = logstoreInstance.id.split('/');
|
|
159
161
|
logConfig = { project, logstore };
|
|
@@ -172,7 +174,7 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
172
174
|
],
|
|
173
175
|
};
|
|
174
176
|
if (cloudTrust && !(0, common_1.attributesEqual)(cloudTrust, desiredTrust)) {
|
|
175
|
-
return
|
|
177
|
+
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
176
178
|
}
|
|
177
179
|
// b. execution + custom policy (the `<roleName>-policy` custom document). An
|
|
178
180
|
// absent/unreadable cloud document is drift: the executor recreates it on
|
|
@@ -183,7 +185,7 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
183
185
|
if (!cloudPolicy ||
|
|
184
186
|
!desiredPolicyDocument ||
|
|
185
187
|
!(0, common_1.attributesEqual)(cloudPolicy, desiredPolicyDocument)) {
|
|
186
|
-
return
|
|
188
|
+
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
187
189
|
}
|
|
188
190
|
// c. managed (system) policies as sorted name sets; desired ARNs strip the
|
|
189
191
|
// `acs:ram::<uid>:policy/` prefix.
|
|
@@ -191,15 +193,16 @@ const detectRolePolicyDrift = async (context, state, fn, currentState, roleName,
|
|
|
191
193
|
const cloudManagedNames = await (0, refreshCache_1.cachedRefreshRead)(context, `ram.listAttachedRolePolicies:${roleName}`, () => client.ram.listAttachedRolePolicies(roleName));
|
|
192
194
|
const asSortedSetKey = (names) => [...names].sort().join(',');
|
|
193
195
|
if (asSortedSetKey(desiredManagedNames) !== asSortedSetKey(cloudManagedNames ?? [])) {
|
|
194
|
-
return
|
|
196
|
+
return 'PLAN_DRIFT_ROLE_POLICY';
|
|
195
197
|
}
|
|
196
|
-
return
|
|
198
|
+
return null;
|
|
197
199
|
};
|
|
198
200
|
/**
|
|
199
201
|
* Issue #234 M1: nested log-drift probe — logstore ttl/shards and index
|
|
200
202
|
* presence for functions that declare logging. The logstore is per-function
|
|
201
203
|
* (buildFunctionLogstoreName), so this lives in the function flow. Aliyun
|
|
202
204
|
* cannot shrink shards, so only a shard deficit counts as drift.
|
|
205
|
+
* Returns an i18n drift-reason key (issue #246); null means no drift.
|
|
203
206
|
*/
|
|
204
207
|
const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
205
208
|
// Each declared dimension contributes its own probe; undeclared dimensions
|
|
@@ -211,18 +214,18 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
211
214
|
if (projectName && logstoreName) {
|
|
212
215
|
const logstore = await (0, refreshCache_1.cachedRefreshRead)(context, `sls.getLogstore:${projectName}:${logstoreName}`, () => client.sls.getLogstore(projectName, logstoreName));
|
|
213
216
|
if (!logstore) {
|
|
214
|
-
return
|
|
217
|
+
return 'PLAN_DRIFT_LOGSTORE'; // logstore deleted out-of-band
|
|
215
218
|
}
|
|
216
219
|
if (logstore.ttl !== slsOperations_1.SLS_LOGSTORE_TTL) {
|
|
217
|
-
return
|
|
220
|
+
return 'PLAN_DRIFT_LOGSTORE';
|
|
218
221
|
}
|
|
219
222
|
// Aliyun cannot shrink shards — only a deficit counts as drift.
|
|
220
223
|
if ((logstore.shardCount ?? 0) < slsOperations_1.SLS_LOGSTORE_SHARDS) {
|
|
221
|
-
return
|
|
224
|
+
return 'PLAN_DRIFT_LOGSTORE';
|
|
222
225
|
}
|
|
223
226
|
const index = await (0, refreshCache_1.cachedRefreshRead)(context, `sls.getIndex:${projectName}:${logstoreName}`, () => client.sls.getIndex(projectName, logstoreName));
|
|
224
227
|
if (!index) {
|
|
225
|
-
return
|
|
228
|
+
return 'PLAN_DRIFT_LOGSTORE'; // index deleted out-of-band
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
231
|
}
|
|
@@ -256,7 +259,7 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
256
259
|
liveIngress.some((l) => !desired.ingress.includes(l)) ||
|
|
257
260
|
desired.egress.some((d) => !liveEgress.includes(d)) ||
|
|
258
261
|
liveEgress.some((l) => !desired.egress.includes(l))) {
|
|
259
|
-
return
|
|
262
|
+
return 'PLAN_DRIFT_SG_RULES';
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
}
|
|
@@ -271,11 +274,11 @@ const detectFunctionNestedDrift = async (context, client, fn, currentState) => {
|
|
|
271
274
|
}
|
|
272
275
|
const targets = await (0, refreshCache_1.cachedRefreshRead)(context, `nas.listMountTargets:${fsId}`, () => client.nas.listMountTargets(fsId));
|
|
273
276
|
if (!targets || targets.length === 0) {
|
|
274
|
-
return
|
|
277
|
+
return 'PLAN_DRIFT_NAS_MOUNT'; // mount target deleted out-of-band
|
|
275
278
|
}
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
|
-
return
|
|
281
|
+
return null;
|
|
279
282
|
};
|
|
280
283
|
const generateFunctionPlan = async (context, state, functions) => {
|
|
281
284
|
if (!functions || functions.length === 0) {
|
|
@@ -302,7 +305,11 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
302
305
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
303
306
|
const remoteFunction = await (0, refreshCache_1.cachedRefreshRead)(context, `fc3.getFunction:${fn.name}`, () => client.fc3.getFunction(fn.name));
|
|
304
307
|
if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.tags)) {
|
|
305
|
-
throw new Error(
|
|
308
|
+
throw new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED', {
|
|
309
|
+
resourceType: 'Function',
|
|
310
|
+
resourceName: fn.name,
|
|
311
|
+
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
312
|
+
}));
|
|
306
313
|
}
|
|
307
314
|
return {
|
|
308
315
|
logicalId,
|
|
@@ -346,15 +353,21 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
346
353
|
// (memory/timeout/env/...). One-directional: only mapper-emitted keys
|
|
347
354
|
// the desired definition declares are compared, so cloud-only extras
|
|
348
355
|
// the config never asked for are ignored (desired-declared contract).
|
|
356
|
+
// Issue #246: the diff baseline is cloud reality — live attributes
|
|
357
|
+
// merged over the stored definition — and revertKeys marks the fields
|
|
358
|
+
// whose difference is purely an out-of-config cloud edit.
|
|
349
359
|
const remoteAttributes = (0, fc3Types_1.cloudFc3ToDefinition)(remoteFunction);
|
|
350
360
|
const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(remoteAttributes, desiredDefinition);
|
|
361
|
+
const liveBefore = normalizeDefinitionForComparison((0, planCompare_1.mergeLiveBefore)(currentState.definition || {}, remoteAttributes));
|
|
362
|
+
const revertKeys = (0, planCompare_1.computeRevertKeys)(normalizedCurrent, normalizeDefinitionForComparison(remoteAttributes), normalizedDesired);
|
|
351
363
|
if (definitionChanged || remoteDiffers) {
|
|
352
364
|
return {
|
|
353
365
|
logicalId,
|
|
354
366
|
action: 'update',
|
|
355
367
|
resourceType: 'ALIYUN_FC3',
|
|
356
|
-
changes: { before:
|
|
368
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
357
369
|
drifted: true,
|
|
370
|
+
...(revertKeys.length ? { revertKeys } : {}),
|
|
358
371
|
};
|
|
359
372
|
}
|
|
360
373
|
const roleProbe = resolveManagedRoleProbe(context, fn, currentState);
|
|
@@ -370,18 +383,20 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
370
383
|
logicalId,
|
|
371
384
|
action: 'update',
|
|
372
385
|
resourceType: 'ALIYUN_FC3',
|
|
373
|
-
changes: { before:
|
|
386
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
374
387
|
drifted: true,
|
|
388
|
+
driftReasons: ['PLAN_DRIFT_ROLE_MISSING'],
|
|
375
389
|
};
|
|
376
390
|
}
|
|
377
|
-
const
|
|
378
|
-
if (
|
|
391
|
+
const roleDriftReason = await detectRolePolicyDrift(context, state, fn, currentState, roleProbe.roleName, cloudRole);
|
|
392
|
+
if (roleDriftReason) {
|
|
379
393
|
return {
|
|
380
394
|
logicalId,
|
|
381
395
|
action: 'update',
|
|
382
396
|
resourceType: 'ALIYUN_FC3',
|
|
383
|
-
changes: { before:
|
|
397
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
384
398
|
drifted: true,
|
|
399
|
+
driftReasons: [roleDriftReason],
|
|
385
400
|
};
|
|
386
401
|
}
|
|
387
402
|
}
|
|
@@ -396,14 +411,15 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
396
411
|
// Issue #234 M1/M2: nested drift probe — the probe itself skips
|
|
397
412
|
// dimensions the config does not declare.
|
|
398
413
|
try {
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
414
|
+
const nestedDriftReason = await detectFunctionNestedDrift(context, client, fn, currentState);
|
|
415
|
+
if (nestedDriftReason) {
|
|
401
416
|
return {
|
|
402
417
|
logicalId,
|
|
403
418
|
action: 'update',
|
|
404
419
|
resourceType: 'ALIYUN_FC3',
|
|
405
|
-
changes: { before:
|
|
420
|
+
changes: { before: liveBefore, after: normalizedDesired },
|
|
406
421
|
drifted: true,
|
|
422
|
+
driftReasons: [nestedDriftReason],
|
|
407
423
|
};
|
|
408
424
|
}
|
|
409
425
|
}
|
|
@@ -415,7 +431,11 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
415
431
|
}
|
|
416
432
|
return { logicalId, action: 'noop', resourceType: 'ALIYUN_FC3' };
|
|
417
433
|
}
|
|
418
|
-
catch {
|
|
434
|
+
catch (error) {
|
|
435
|
+
common_1.logger.warn(lang_1.lang.__('PLAN_LIVE_READ_FAILED', {
|
|
436
|
+
logicalId,
|
|
437
|
+
error: error instanceof Error ? error.message : String(error),
|
|
438
|
+
}));
|
|
419
439
|
return {
|
|
420
440
|
logicalId,
|
|
421
441
|
action: 'create',
|
|
@@ -424,6 +444,7 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
424
444
|
before: normalizeDefinitionForComparison(currentState.definition),
|
|
425
445
|
after: normalizeDefinitionForComparison(desiredDefinition),
|
|
426
446
|
},
|
|
447
|
+
drifted: true,
|
|
427
448
|
};
|
|
428
449
|
}
|
|
429
450
|
});
|