@geek-fun/serverlessinsight 0.8.2 → 0.8.4
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 +15 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +5 -2
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +363 -30
- package/dist/src/common/aliyunClient/esOperations.js +43 -29
- package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
- package/dist/src/common/aliyunClient/ossOperations.js +165 -13
- package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
- package/dist/src/common/aliyunClient/slsOperations.js +90 -28
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +13 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +10 -4
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +186 -14
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +43 -2
- package/dist/src/common/tencentClient/scfOperations.js +266 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +91 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +305 -171
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +107 -1
- package/dist/src/lang/zh-CN.js +107 -1
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +16 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +27 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +416 -94
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +58 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +15 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +21 -3
- package/dist/src/stack/scfStack/scfResource.js +686 -24
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +434 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +13 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +78 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +32 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractEventDomainDefinition = exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.eventToApigwGroupConfig = void 0;
|
|
3
|
+
exports.extractEventDomainDefinition = exports.buildEventLogSnapshot = exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.eventToApigwGroupConfig = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
6
7
|
/**
|
|
7
8
|
* Convert EventDomain to API Gateway group config
|
|
9
|
+
*
|
|
10
|
+
* When a context + logicalId are supplied, the config carries the ownership
|
|
11
|
+
* tag that lets a later run idempotently adopt the group created here (state
|
|
12
|
+
* reset or mid-run failure) without risking takeover of a same-named group
|
|
13
|
+
* that belongs to another project.
|
|
8
14
|
*/
|
|
9
|
-
const eventToApigwGroupConfig = (event, serviceName, stage) => {
|
|
10
|
-
|
|
15
|
+
const eventToApigwGroupConfig = (event, serviceName, stage, context, logicalId) => {
|
|
16
|
+
const groupConfig = {
|
|
11
17
|
groupName: `${serviceName}-${stage}-agw-group`.replace(/_/g, '-'),
|
|
12
18
|
description: `API Gateway group for ${serviceName}`,
|
|
13
19
|
};
|
|
20
|
+
if (context && logicalId) {
|
|
21
|
+
groupConfig.tags = [
|
|
22
|
+
{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) },
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
return groupConfig;
|
|
14
26
|
};
|
|
15
27
|
exports.eventToApigwGroupConfig = eventToApigwGroupConfig;
|
|
16
28
|
/**
|
|
@@ -61,7 +73,8 @@ const triggerToApigwApiConfig = (event, trigger, groupId, serviceName, region, s
|
|
|
61
73
|
const protocolConfig = (0, exports.inferProtocolConfig)(event.domain?.protocol);
|
|
62
74
|
return {
|
|
63
75
|
groupId,
|
|
64
|
-
|
|
76
|
+
// Aliyun CreateApi requires 4-50 chars of [A-Za-z0-9_] — no hyphens.
|
|
77
|
+
apiName: `${event.name.replace(/-/g, '_')}_${stage}_agw_api_${apiKey}`.slice(0, 50),
|
|
65
78
|
visibility: 'PRIVATE',
|
|
66
79
|
authType: 'ANONYMOUS',
|
|
67
80
|
requestConfig: {
|
|
@@ -189,6 +202,24 @@ const getDomainCdnConfig = (domain) => {
|
|
|
189
202
|
: {}),
|
|
190
203
|
};
|
|
191
204
|
};
|
|
205
|
+
/**
|
|
206
|
+
* Snapshot of the event-level access-log wiring (issue #214): the app-scoped
|
|
207
|
+
* shared SLS project plus the service-scoped gateway logstore. Omitted when the
|
|
208
|
+
* event does not opt into logging so existing state definitions stay identical.
|
|
209
|
+
*/
|
|
210
|
+
const buildEventLogSnapshot = (event, context) => {
|
|
211
|
+
if (!event.log) {
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
logEnabled: event.log === true || event.log === 'true',
|
|
216
|
+
logConfig: {
|
|
217
|
+
project: `${context.app}-${context.stage}-sls`,
|
|
218
|
+
logstore: `${context.service}-${context.stage}-apigw-logs`,
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
exports.buildEventLogSnapshot = buildEventLogSnapshot;
|
|
192
223
|
const extractEventDomainDefinition = (domain) => {
|
|
193
224
|
if (!domain) {
|
|
194
225
|
return null;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeDatabasePlan = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const databaseResource_1 = require("./databaseResource");
|
|
5
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
9
|
const lang_1 = require("../../lang");
|
|
8
10
|
const getResourceTypeName = (resourceType) => resourceType === 'ALIYUN_ES_SERVERLESS' ? 'Elasticsearch Serverless' : 'RDS Serverless';
|
|
@@ -97,13 +99,26 @@ const executeDatabasePlan = async (context, plan, databases, initialState, onSta
|
|
|
97
99
|
const successfulItems = [];
|
|
98
100
|
let currentState = initialState;
|
|
99
101
|
for (const item of plan.items) {
|
|
102
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
103
|
+
type: 'resource_pre',
|
|
104
|
+
logicalId: item.logicalId,
|
|
105
|
+
resourceType: item.resourceType,
|
|
106
|
+
action: item.action,
|
|
107
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
108
|
+
});
|
|
109
|
+
const __siStartedAt = Date.now();
|
|
100
110
|
try {
|
|
101
111
|
const newState = await executeSingleItem(context, item, databasesMap, currentState);
|
|
102
112
|
if (newState !== null) {
|
|
103
113
|
currentState = newState;
|
|
104
114
|
successfulItems.push(item);
|
|
115
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
116
|
+
type: 'resource_complete',
|
|
117
|
+
logicalId: item.logicalId,
|
|
118
|
+
durationMs: Date.now() - __siStartedAt,
|
|
119
|
+
});
|
|
105
120
|
if (onStateChange) {
|
|
106
|
-
onStateChange(currentState);
|
|
121
|
+
await onStateChange(currentState);
|
|
107
122
|
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
108
123
|
action: item.action,
|
|
109
124
|
resourceId: item.logicalId,
|
|
@@ -112,6 +127,29 @@ const executeDatabasePlan = async (context, plan, databases, initialState, onSta
|
|
|
112
127
|
}
|
|
113
128
|
}
|
|
114
129
|
catch (error) {
|
|
130
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
131
|
+
type: 'resource_failed',
|
|
132
|
+
logicalId: item.logicalId,
|
|
133
|
+
severity: 'error',
|
|
134
|
+
durationMs: Date.now() - __siStartedAt,
|
|
135
|
+
error: {
|
|
136
|
+
message: error instanceof Error ? error.message : String(error),
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
if (error instanceof types_1.PartialResourceError) {
|
|
140
|
+
const updatedState = error.updatedState;
|
|
141
|
+
if (onStateChange) {
|
|
142
|
+
await onStateChange(updatedState);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
state: updatedState,
|
|
146
|
+
partialFailure: {
|
|
147
|
+
failedItem: item,
|
|
148
|
+
error: error.cause,
|
|
149
|
+
successfulItems,
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
115
153
|
return {
|
|
116
154
|
state: currentState,
|
|
117
155
|
partialFailure: {
|
|
@@ -6,6 +6,8 @@ const rdsTypes_1 = require("./rdsTypes");
|
|
|
6
6
|
const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
7
7
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
8
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
9
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
10
|
+
const toOwnershipTagShape = (tags) => tags?.map((t) => ({ Key: t.key, Value: t.value }));
|
|
9
11
|
const planDatabaseDeletion = (logicalId, definition, resourceType) => ({
|
|
10
12
|
logicalId,
|
|
11
13
|
action: 'delete',
|
|
@@ -64,7 +66,17 @@ const generateDatabasePlan = async (context, state, databases) => {
|
|
|
64
66
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
65
67
|
const resourceType = getResourceType(database);
|
|
66
68
|
const desiredDefinition = getDesiredDefinition(database);
|
|
67
|
-
if (!currentState) {
|
|
69
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
70
|
+
// No usable local state: probe the provider before planning create.
|
|
71
|
+
// If a same-named resource already exists WITHOUT our ownership tag it
|
|
72
|
+
// may belong to another project — fail fast in the plan instead of
|
|
73
|
+
// letting the executor discover it mid-deploy.
|
|
74
|
+
const remote = resourceType === 'ALIYUN_ES_SERVERLESS'
|
|
75
|
+
? await client.es.getApp(database.name)
|
|
76
|
+
: await client.rds.getInstanceByName(database.name);
|
|
77
|
+
if (remote && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(remote.tags))) {
|
|
78
|
+
throw new Error(`${resourceType} ${database.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
79
|
+
}
|
|
68
80
|
return {
|
|
69
81
|
logicalId,
|
|
70
82
|
action: 'create',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteDatabaseResource = exports.updateDatabaseResource = exports.readDatabaseResource = exports.createDatabaseResource = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
6
|
const rdsTypes_1 = require("./rdsTypes");
|
|
6
7
|
const esServerlessTypes_1 = require("./esServerlessTypes");
|
|
@@ -8,6 +9,17 @@ const stateManager_1 = require("../../common/stateManager");
|
|
|
8
9
|
const common_1 = require("../../common");
|
|
9
10
|
const logger_1 = require("../../common/logger");
|
|
10
11
|
const lang_1 = require("../../lang");
|
|
12
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
13
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
14
|
+
// Normalize provider tag shape ({key,value}) to the ownership-check shape ({Key,Value}).
|
|
15
|
+
const toOwnershipTagShape = (tags) => tags?.map((t) => ({ Key: t.key, Value: t.value }));
|
|
16
|
+
// RDS CreateDBInstance reports a name collision as InvalidDBInstanceName.Duplicate
|
|
17
|
+
// ("Specified DB instance name already exists in the Aliyun RDS"). ES Serverless
|
|
18
|
+
// does not publish its CreateApp collision code in the SDK — DuplicateResource is
|
|
19
|
+
// Aliyun's common "resource already exists" code, and the generic matcher in
|
|
20
|
+
// alreadyExists.ts additionally catches '已存在'/'already exist' messages.
|
|
21
|
+
const RDS_ALREADY_EXISTS_CODES = ['InvalidDBInstanceName.Duplicate'];
|
|
22
|
+
const ES_ALREADY_EXISTS_CODES = ['DuplicateResource'];
|
|
11
23
|
const buildRdsInstanceFromProvider = (info, sid) => {
|
|
12
24
|
return {
|
|
13
25
|
sid,
|
|
@@ -39,6 +51,36 @@ const buildRdsInstanceFromProvider = (info, sid) => {
|
|
|
39
51
|
regionId: info.regionId ?? null,
|
|
40
52
|
securityIPList: info.securityIPList ?? null,
|
|
41
53
|
multiAZ: info.multiAZ ?? null,
|
|
54
|
+
tags: info.tags
|
|
55
|
+
? info.tags.map((t) => ({
|
|
56
|
+
key: t.key ?? null,
|
|
57
|
+
value: t.value ?? null,
|
|
58
|
+
}))
|
|
59
|
+
: [],
|
|
60
|
+
dbInstanceCpu: info.dbInstanceCpu ?? null,
|
|
61
|
+
dbInstanceMemory: info.dbInstanceMemory ?? null,
|
|
62
|
+
payType: info.payType ?? null,
|
|
63
|
+
expireTime: info.expireTime ?? null,
|
|
64
|
+
maintainTime: info.maintainTime ?? null,
|
|
65
|
+
maxConnections: info.maxConnections ?? null,
|
|
66
|
+
maxIOPS: info.maxIOPS ?? null,
|
|
67
|
+
resourceGroupId: info.resourceGroupId ?? null,
|
|
68
|
+
deletionProtection: info.deletionProtection ?? null,
|
|
69
|
+
lockMode: info.lockMode ?? null,
|
|
70
|
+
lockReason: info.lockReason ?? null,
|
|
71
|
+
connectionMode: info.connectionMode ?? null,
|
|
72
|
+
dbInstanceDiskUsed: info.dbInstanceDiskUsed ?? null,
|
|
73
|
+
dbInstanceType: info.dbInstanceType ?? null,
|
|
74
|
+
instanceNetworkType: info.instanceNetworkType ?? null,
|
|
75
|
+
timeZone: info.timeZone ?? null,
|
|
76
|
+
currentKernelVersion: info.currentKernelVersion ?? null,
|
|
77
|
+
latestKernelVersion: info.latestKernelVersion ?? null,
|
|
78
|
+
masterZone: info.masterZone ?? null,
|
|
79
|
+
masterInstanceId: info.masterInstanceId ?? null,
|
|
80
|
+
slaveZones: info.slaveZones?.map((z) => ({ zoneId: z.zoneId ?? null })) ?? [],
|
|
81
|
+
readOnlyDBInstanceIds: info.readOnlyDBInstanceIds ?? [],
|
|
82
|
+
burstingEnabled: info.burstingEnabled ?? null,
|
|
83
|
+
computeBurstEnabled: info.computeBurstEnabled ?? null,
|
|
42
84
|
};
|
|
43
85
|
};
|
|
44
86
|
const buildEsInstanceFromProvider = (info, sid) => {
|
|
@@ -98,60 +140,113 @@ const buildEsInstanceFromProvider = (info, sid) => {
|
|
|
98
140
|
};
|
|
99
141
|
const createDatabaseResource = async (context, database, state) => {
|
|
100
142
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
let resourceType;
|
|
105
|
-
if (database.type === "ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */) {
|
|
106
|
-
// Create Elasticsearch Serverless app
|
|
107
|
-
const config = (0, esServerlessTypes_1.databaseToEsConfig)(database);
|
|
108
|
-
instanceId = await client.es.createApp(config);
|
|
109
|
-
// Refresh state from provider to get all attributes
|
|
110
|
-
const appInfo = await client.es.getApp(instanceId);
|
|
111
|
-
if (!appInfo) {
|
|
112
|
-
throw new Error(`Failed to refresh state for ES app: ${instanceId}`);
|
|
113
|
-
}
|
|
114
|
-
definition = (0, esServerlessTypes_1.extractEsDefinition)(config);
|
|
115
|
-
const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
|
|
116
|
-
instance = buildEsInstanceFromProvider(appInfo, sid);
|
|
117
|
-
resourceType = 'ALIYUN_ES_SERVERLESS';
|
|
118
|
-
}
|
|
119
|
-
else if ([
|
|
143
|
+
const logicalId = `databases.${database.key}`;
|
|
144
|
+
const isEs = database.type === "ELASTICSEARCH_SERVERLESS" /* DatabaseEnum.ELASTICSEARCH_SERVERLESS */;
|
|
145
|
+
const isRds = [
|
|
120
146
|
"RDS_MYSQL_SERVERLESS" /* DatabaseEnum.RDS_MYSQL_SERVERLESS */,
|
|
121
147
|
"RDS_PGSQL_SERVERLESS" /* DatabaseEnum.RDS_PGSQL_SERVERLESS */,
|
|
122
148
|
"RDS_MSSQL_SERVERLESS" /* DatabaseEnum.RDS_MSSQL_SERVERLESS */,
|
|
123
|
-
].includes(database.type)
|
|
124
|
-
|
|
125
|
-
const config = (0, rdsTypes_1.databaseToRdsConfig)(database);
|
|
126
|
-
instanceId = await client.rds.createInstance(config);
|
|
127
|
-
// Refresh state from provider to get all attributes
|
|
128
|
-
const rdsInfo = await client.rds.getInstance(instanceId);
|
|
129
|
-
if (!rdsInfo) {
|
|
130
|
-
throw new Error(`Failed to refresh state for RDS instance: ${instanceId}`);
|
|
131
|
-
}
|
|
132
|
-
definition = (0, rdsTypes_1.extractRdsDefinition)(config);
|
|
133
|
-
const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
|
|
134
|
-
instance = buildRdsInstanceFromProvider(rdsInfo, sid);
|
|
135
|
-
resourceType = 'ALIYUN_RDS_SERVERLESS';
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
149
|
+
].includes(database.type);
|
|
150
|
+
if (!isEs && !isRds) {
|
|
138
151
|
throw new Error(`Unsupported database type: ${database.type}`);
|
|
139
152
|
}
|
|
140
|
-
const
|
|
153
|
+
const resourceType = isEs ? 'ALIYUN_ES_SERVERLESS' : 'ALIYUN_RDS_SERVERLESS';
|
|
154
|
+
const definition = isEs
|
|
155
|
+
? (0, esServerlessTypes_1.extractEsDefinition)((0, esServerlessTypes_1.databaseToEsConfig)(database))
|
|
156
|
+
: (0, rdsTypes_1.extractRdsDefinition)((0, rdsTypes_1.databaseToRdsConfig)(database));
|
|
157
|
+
const taintedResourceState = {
|
|
141
158
|
mode: 'managed',
|
|
142
159
|
region: context.region,
|
|
143
160
|
definition,
|
|
144
|
-
|
|
145
|
-
instances: [instance],
|
|
161
|
+
instances: [],
|
|
146
162
|
lastUpdated: new Date().toISOString(),
|
|
147
163
|
metadata: {
|
|
148
164
|
databaseName: database.name,
|
|
149
|
-
instanceId,
|
|
150
165
|
resourceType,
|
|
151
166
|
},
|
|
167
|
+
status: 'tainted',
|
|
152
168
|
};
|
|
153
|
-
const
|
|
154
|
-
|
|
169
|
+
const stateAfterDependents = (0, stateManager_1.setResource)(state, logicalId, taintedResourceState);
|
|
170
|
+
try {
|
|
171
|
+
let instanceId;
|
|
172
|
+
let instance;
|
|
173
|
+
if (isEs) {
|
|
174
|
+
const config = (0, esServerlessTypes_1.databaseToEsConfig)(database);
|
|
175
|
+
config.tags = [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }];
|
|
176
|
+
try {
|
|
177
|
+
instanceId = await client.es.createApp(config);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ES_ALREADY_EXISTS_CODES)) {
|
|
181
|
+
const probe = await client.es.getApp(config.appName);
|
|
182
|
+
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(probe.tags))) {
|
|
183
|
+
instanceId = probe.appId ?? config.appName;
|
|
184
|
+
logger_1.logger.info(`ES app ${config.appName} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
throw new Error(`ES app ${config.appName} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`, { cause: error });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Refresh state from provider to get all attributes
|
|
195
|
+
const appInfo = await client.es.getApp(instanceId);
|
|
196
|
+
if (!appInfo) {
|
|
197
|
+
throw new Error(`Failed to refresh state for ES app: ${instanceId}`);
|
|
198
|
+
}
|
|
199
|
+
const sid = (0, common_1.buildSid)('aliyun', 'es', context.stage, instanceId);
|
|
200
|
+
instance = buildEsInstanceFromProvider(appInfo, sid);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const config = (0, rdsTypes_1.databaseToRdsConfig)(database);
|
|
204
|
+
config.tags = [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }];
|
|
205
|
+
try {
|
|
206
|
+
instanceId = await client.rds.createInstance(config);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, RDS_ALREADY_EXISTS_CODES)) {
|
|
210
|
+
const probe = await client.rds.getInstanceByName(config.dbInstanceDescription);
|
|
211
|
+
if (probe?.dbInstanceId &&
|
|
212
|
+
(0, ownershipTag_1.isOwnedByStack)(context, logicalId, toOwnershipTagShape(probe.tags))) {
|
|
213
|
+
instanceId = probe.dbInstanceId;
|
|
214
|
+
logger_1.logger.info(`RDS instance ${config.dbInstanceDescription} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
throw new Error(`RDS instance ${config.dbInstanceDescription} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`, { cause: error });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Refresh state from provider to get all attributes
|
|
225
|
+
const rdsInfo = await client.rds.getInstance(instanceId);
|
|
226
|
+
if (!rdsInfo) {
|
|
227
|
+
throw new Error(`Failed to refresh state for RDS instance: ${instanceId}`);
|
|
228
|
+
}
|
|
229
|
+
const sid = (0, common_1.buildSid)('aliyun', 'rds', context.stage, instanceId);
|
|
230
|
+
instance = buildRdsInstanceFromProvider(rdsInfo, sid);
|
|
231
|
+
}
|
|
232
|
+
const resourceState = {
|
|
233
|
+
mode: 'managed',
|
|
234
|
+
region: context.region,
|
|
235
|
+
definition,
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
237
|
+
instances: [instance],
|
|
238
|
+
lastUpdated: new Date().toISOString(),
|
|
239
|
+
metadata: {
|
|
240
|
+
databaseName: database.name,
|
|
241
|
+
instanceId,
|
|
242
|
+
resourceType,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
return (0, stateManager_1.setResource)(stateAfterDependents, logicalId, resourceState);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
249
|
+
}
|
|
155
250
|
};
|
|
156
251
|
exports.createDatabaseResource = createDatabaseResource;
|
|
157
252
|
const readDatabaseResource = async (context, instanceId, resourceType) => {
|
|
@@ -13,8 +13,8 @@ const tablestorePlanner_1 = require("./tablestorePlanner");
|
|
|
13
13
|
const tablestoreExecutor_1 = require("./tablestoreExecutor");
|
|
14
14
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
15
15
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
16
|
-
const createSaveStateFn = (backend, iac, stage) => (state) => {
|
|
17
|
-
backend.saveState(state, iac.app, iac.service, stage);
|
|
16
|
+
const createSaveStateFn = (backend, iac, stage) => async (state) => {
|
|
17
|
+
await backend.saveState(state, iac.app, iac.service, stage);
|
|
18
18
|
};
|
|
19
19
|
const handlePartialFailure = (failure) => {
|
|
20
20
|
const error = failure.error;
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.destroyAliyunStack = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
|
+
const stateManager_1 = require("../../common/stateManager");
|
|
6
|
+
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
5
7
|
const lang_1 = require("../../lang");
|
|
6
8
|
const fc3Planner_1 = require("./fc3Planner");
|
|
7
9
|
const fc3Executor_1 = require("./fc3Executor");
|
|
@@ -13,8 +15,9 @@ const tablestorePlanner_1 = require("./tablestorePlanner");
|
|
|
13
15
|
const tablestoreExecutor_1 = require("./tablestoreExecutor");
|
|
14
16
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
15
17
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
+
const sharedLogProject_1 = require("./sharedLogProject");
|
|
19
|
+
const createSaveStateFn = (backend, app, service, stage) => async (state) => {
|
|
20
|
+
await backend.saveState(state, app, service, stage);
|
|
18
21
|
};
|
|
19
22
|
const handlePartialFailure = (failure) => {
|
|
20
23
|
const error = failure.error;
|
|
@@ -117,6 +120,28 @@ const destroyAliyunStack = async (backend) => {
|
|
|
117
120
|
],
|
|
118
121
|
});
|
|
119
122
|
}
|
|
123
|
+
// Release the shared SLS project once nothing references it anymore. The
|
|
124
|
+
// per-resource teardowns above deleted their own logstores; the shared
|
|
125
|
+
// project is retained while the regional PROVIDER gateway log config (or a
|
|
126
|
+
// retained ALIYUN_APIGW_LOG_CONFIG instance) still points at it.
|
|
127
|
+
const shared = (0, stateManager_1.getSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
128
|
+
if (shared) {
|
|
129
|
+
const sharedName = (0, sharedLogProject_1.resolveSharedProjectName)(shared);
|
|
130
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
131
|
+
const gatewayConfig = await client.apigw.describeGatewayLogConfig();
|
|
132
|
+
const retainedByGateway = Boolean(sharedName && gatewayConfig?.slsProject === sharedName);
|
|
133
|
+
const retainedByApigwState = Object.values(state.resources ?? {}).some((resourceState) => resourceState.instances?.some((instance) => instance.type === 'ALIYUN_APIGW_LOG_CONFIG' &&
|
|
134
|
+
instance.attributes?.slsProject === sharedName));
|
|
135
|
+
if (retainedByGateway || retainedByApigwState) {
|
|
136
|
+
common_1.logger.info(lang_1.lang.__('SHARED_SLS_PROJECT_IN_USE', { projectName: sharedName ?? '', count: '1' }));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const releaseResult = await (0, sharedLogProject_1.releaseSharedSlsProjectIfUnused)(context, client, shared);
|
|
140
|
+
if (releaseResult === 'deleted') {
|
|
141
|
+
state = (0, stateManager_1.removeSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
120
145
|
await backend.saveState(state, context.app, context.service, context.stage);
|
|
121
146
|
};
|
|
122
147
|
exports.destroyAliyunStack = destroyAliyunStack;
|
|
@@ -4,6 +4,7 @@ exports.executeFunctionPlan = void 0;
|
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const fc3Resource_1 = require("./fc3Resource");
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
7
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
8
9
|
const lang_1 = require("../../lang");
|
|
9
10
|
const executeCreateAction = async (context, fn, currentState) => {
|
|
@@ -62,21 +63,43 @@ const executeFunctionPlan = async (context, plan, functions, initialState, onSta
|
|
|
62
63
|
const successfulItems = [];
|
|
63
64
|
let currentState = initialState;
|
|
64
65
|
for (const item of plan.items) {
|
|
66
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
67
|
+
type: 'resource_pre',
|
|
68
|
+
logicalId: item.logicalId,
|
|
69
|
+
resourceType: item.resourceType,
|
|
70
|
+
action: item.action,
|
|
71
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
72
|
+
});
|
|
73
|
+
const __siStartedAt = Date.now();
|
|
65
74
|
try {
|
|
66
75
|
const newState = await executeSingleItem(context, item, functionsMap, currentState);
|
|
67
76
|
if (newState !== null) {
|
|
68
77
|
currentState = newState;
|
|
69
78
|
successfulItems.push(item);
|
|
79
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
80
|
+
type: 'resource_complete',
|
|
81
|
+
logicalId: item.logicalId,
|
|
82
|
+
durationMs: Date.now() - __siStartedAt,
|
|
83
|
+
});
|
|
70
84
|
if (onStateChange) {
|
|
71
|
-
onStateChange(currentState);
|
|
85
|
+
await onStateChange(currentState);
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
catch (error) {
|
|
90
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
91
|
+
type: 'resource_failed',
|
|
92
|
+
logicalId: item.logicalId,
|
|
93
|
+
severity: 'error',
|
|
94
|
+
durationMs: Date.now() - __siStartedAt,
|
|
95
|
+
error: {
|
|
96
|
+
message: error instanceof Error ? error.message : String(error),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
76
99
|
if (error instanceof types_1.PartialResourceError) {
|
|
77
100
|
const updatedState = error.updatedState;
|
|
78
101
|
if (onStateChange) {
|
|
79
|
-
onStateChange(updatedState);
|
|
102
|
+
await onStateChange(updatedState);
|
|
80
103
|
}
|
|
81
104
|
return {
|
|
82
105
|
state: updatedState,
|
|
@@ -5,6 +5,7 @@ const common_1 = require("../../common");
|
|
|
5
5
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
6
6
|
const fc3Types_1 = require("./fc3Types");
|
|
7
7
|
const lang_1 = require("../../lang");
|
|
8
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
9
|
/**
|
|
9
10
|
* Provider-managed logConfig fields that are set by the system after creation.
|
|
10
11
|
* These should not be compared when detecting changes.
|
|
@@ -77,10 +78,19 @@ const generateFunctionPlan = async (context, state, functions) => {
|
|
|
77
78
|
const rawConfig = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
78
79
|
const config = await resolveVpcConfigSecurityGroup(context, rawConfig);
|
|
79
80
|
const codePath = fn.code.path;
|
|
80
|
-
const desiredCodeHash = (0, common_1.
|
|
81
|
+
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
81
82
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
|
|
82
83
|
const desiredDefinition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
83
84
|
if (!currentState || currentState.status === 'tainted') {
|
|
85
|
+
// No usable local state: probe the provider before planning create.
|
|
86
|
+
// If a same-named function already exists WITHOUT our ownership tag it
|
|
87
|
+
// may belong to another project — fail fast in the plan instead of
|
|
88
|
+
// letting the executor discover it mid-deploy.
|
|
89
|
+
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
90
|
+
const remoteFunction = await client.fc3.getFunction(fn.name);
|
|
91
|
+
if (remoteFunction && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteFunction.tags)) {
|
|
92
|
+
throw new Error(`Function ${fn.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
93
|
+
}
|
|
84
94
|
return {
|
|
85
95
|
logicalId,
|
|
86
96
|
action: 'create',
|