@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
|
@@ -13,6 +13,9 @@ const types_1 = require("../../types");
|
|
|
13
13
|
const fc3Types_1 = require("./fc3Types");
|
|
14
14
|
const logger_1 = require("../../common/logger");
|
|
15
15
|
const lang_1 = require("../../lang");
|
|
16
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
17
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
18
|
+
const sharedLogProject_1 = require("./sharedLogProject");
|
|
16
19
|
const RECOVERY_GET_FUNCTION_DELAY_MS = 1500;
|
|
17
20
|
const delay = async (ms) => {
|
|
18
21
|
await new Promise((resolve) => {
|
|
@@ -51,7 +54,7 @@ const ensureOssCodeUpload = async (client, codePath, region, functionName) => {
|
|
|
51
54
|
logger_1.logger.info(lang_1.lang.__('CREATING_BOOTSTRAP_BUCKET', { bucketName }));
|
|
52
55
|
await client.oss.createBucket({ bucketName });
|
|
53
56
|
}
|
|
54
|
-
const codeHash = (0, common_1.
|
|
57
|
+
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
55
58
|
const ossObjectName = `fc3-code/${functionName}/${codeHash}.zip`;
|
|
56
59
|
await client.oss.putFile(bucketName, ossObjectName, codePath);
|
|
57
60
|
logger_1.logger.info(lang_1.lang.__('UPLOADED_CODE_TO_OSS', { bucketName, objectName: ossObjectName }));
|
|
@@ -63,6 +66,7 @@ const buildFc3InstanceFromProvider = (info, sid) => {
|
|
|
63
66
|
sid,
|
|
64
67
|
id: info.functionName ?? '',
|
|
65
68
|
functionName: info.functionName ?? null,
|
|
69
|
+
functionArn: info.functionArn ?? null,
|
|
66
70
|
functionId: info.functionId ?? null,
|
|
67
71
|
runtime: info.runtime ?? null,
|
|
68
72
|
handler: info.handler ?? null,
|
|
@@ -126,12 +130,26 @@ const buildFc3InstanceFromProvider = (info, sid) => {
|
|
|
126
130
|
lastUpdateStatus: info.lastUpdateStatus ?? null,
|
|
127
131
|
lastUpdateStatusReason: info.lastUpdateStatusReason ?? null,
|
|
128
132
|
lastUpdateStatusReasonCode: info.lastUpdateStatusReasonCode ?? null,
|
|
133
|
+
tags: info.tags?.map((tag) => ({
|
|
134
|
+
key: tag.Key ?? null,
|
|
135
|
+
value: tag.Value ?? null,
|
|
136
|
+
})),
|
|
129
137
|
};
|
|
130
138
|
};
|
|
131
|
-
const
|
|
139
|
+
const buildHttpTriggerConfig = (trigger) => {
|
|
140
|
+
const authType = (0, common_1.mapAuthType)(common_1.ProviderEnum.ALIYUN, trigger.auth_type);
|
|
141
|
+
const { disableURLInternet } = (0, common_1.mapAliyunAccess)(trigger.access);
|
|
142
|
+
return {
|
|
143
|
+
authType,
|
|
144
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH'],
|
|
145
|
+
...(disableURLInternet !== undefined ? { disableURLInternet } : {}),
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const createDependentResources = async (context, fn, serviceName, existingInstances = [], state) => {
|
|
132
149
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
133
150
|
const instances = [];
|
|
134
151
|
let logConfig;
|
|
152
|
+
let sharedProject;
|
|
135
153
|
let securityGroup;
|
|
136
154
|
let nasConfig;
|
|
137
155
|
const hasSlsProject = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
@@ -149,29 +167,20 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
169
|
else {
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_PROJECT', { projectName }));
|
|
155
|
-
const project = await client.sls.createProject(projectName);
|
|
156
|
-
instances.push({ type: 'ALIYUN_SLS_PROJECT', id: projectName, attributes: { ...project } });
|
|
157
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_LOGSTORE', { logstoreName }));
|
|
158
|
-
const logstore = await client.sls.createLogstore(projectName, logstoreName);
|
|
170
|
+
const shared = await (0, sharedLogProject_1.ensureSharedSlsProject)(context, client, state);
|
|
171
|
+
const logstore = await (0, sharedLogProject_1.ensureFunctionLogstore)(context, client, shared.projectName);
|
|
159
172
|
instances.push({
|
|
160
173
|
type: 'ALIYUN_SLS_LOGSTORE',
|
|
161
|
-
id: `${projectName}/${logstoreName}`,
|
|
162
|
-
attributes: {
|
|
174
|
+
id: `${shared.projectName}/${logstore.logstoreName}`,
|
|
175
|
+
attributes: { logstoreName: logstore.logstoreName },
|
|
163
176
|
});
|
|
164
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_SLS_INDEX', { logstoreName }));
|
|
165
|
-
const index = await client.sls.createIndex(projectName, logstoreName);
|
|
166
177
|
instances.push({
|
|
167
178
|
type: 'ALIYUN_SLS_INDEX',
|
|
168
|
-
id: `${projectName}/${logstoreName}/index`,
|
|
169
|
-
attributes: {
|
|
179
|
+
id: `${shared.projectName}/${logstore.logstoreName}/index`,
|
|
180
|
+
attributes: { projectName: shared.projectName, logstoreName: logstore.logstoreName },
|
|
170
181
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
await client.sls.waitForLogstore(projectName, logstoreName);
|
|
174
|
-
logConfig = { project: projectName, logstore: logstoreName };
|
|
182
|
+
logConfig = { project: shared.projectName, logstore: logstore.logstoreName };
|
|
183
|
+
sharedProject = (0, sharedLogProject_1.buildSharedProjectResourceState)(context, shared);
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
const iamConfig = fn.iam?.role;
|
|
@@ -303,67 +312,69 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
303
312
|
role,
|
|
304
313
|
securityGroup,
|
|
305
314
|
nasConfig,
|
|
315
|
+
sharedProject,
|
|
306
316
|
instances,
|
|
307
317
|
};
|
|
308
318
|
};
|
|
309
319
|
const deleteDependentResources = async (context, instances) => {
|
|
310
320
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
311
321
|
for (const instance of [...instances].reverse()) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
case 'ALIYUN_NAS_FILE_SYSTEM':
|
|
321
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_FILE_SYSTEM', { id: instance.id }));
|
|
322
|
-
await client.nas.deleteFileSystem(instance.id);
|
|
323
|
-
break;
|
|
324
|
-
case 'ALIYUN_NAS_ACCESS_GROUP':
|
|
325
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_ACCESS_GROUP', { id: instance.id }));
|
|
326
|
-
await client.nas.deleteAccessGroup(instance.id);
|
|
327
|
-
break;
|
|
328
|
-
case 'ALIYUN_ECS_SECURITY_GROUP':
|
|
329
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SECURITY_GROUP', { id: instance.id }));
|
|
330
|
-
await client.ecs.deleteSecurityGroup(instance.id);
|
|
331
|
-
break;
|
|
332
|
-
case 'ALIYUN_RAM_ROLE': {
|
|
333
|
-
const ramInstance = instance;
|
|
334
|
-
if (ramInstance.external)
|
|
335
|
-
break; // Skip external roles
|
|
336
|
-
const managedPolicies = ramInstance.managedPolicies;
|
|
337
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_RAM_ROLE', { id: instance.id }));
|
|
338
|
-
await client.ram.deleteRole(instance.id, managedPolicies);
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
case 'ALIYUN_SLS_INDEX': {
|
|
342
|
-
const [projectName, logstoreName] = instance.id.split('/');
|
|
343
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: instance.id }));
|
|
344
|
-
await client.sls.deleteIndex(projectName, logstoreName);
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
case 'ALIYUN_SLS_LOGSTORE': {
|
|
348
|
-
const [projectName, logstoreName] = instance.id.split('/');
|
|
349
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: instance.id }));
|
|
350
|
-
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
case 'ALIYUN_SLS_PROJECT':
|
|
354
|
-
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_PROJECT', { id: instance.id }));
|
|
355
|
-
await client.sls.deleteProject(instance.id);
|
|
356
|
-
break;
|
|
357
|
-
default:
|
|
358
|
-
logger_1.logger.warn(lang_1.lang.__('UNKNOWN_RESOURCE_TYPE', { type: instance.type }));
|
|
322
|
+
switch (instance.type) {
|
|
323
|
+
case 'ALIYUN_NAS_MOUNT_TARGET': {
|
|
324
|
+
const [fileSystemId, mountTargetDomain] = instance.id.split('/');
|
|
325
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_MOUNT_TARGET', { id: instance.id }));
|
|
326
|
+
await client.nas.deleteMountTarget(fileSystemId, mountTargetDomain);
|
|
327
|
+
break;
|
|
359
328
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
329
|
+
case 'ALIYUN_NAS_FILE_SYSTEM':
|
|
330
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_FILE_SYSTEM', { id: instance.id }));
|
|
331
|
+
await client.nas.deleteFileSystem(instance.id);
|
|
332
|
+
break;
|
|
333
|
+
case 'ALIYUN_NAS_ACCESS_GROUP':
|
|
334
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_NAS_ACCESS_GROUP', { id: instance.id }));
|
|
335
|
+
await client.nas.deleteAccessGroup(instance.id);
|
|
336
|
+
break;
|
|
337
|
+
case 'ALIYUN_ECS_SECURITY_GROUP':
|
|
338
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SECURITY_GROUP', { id: instance.id }));
|
|
339
|
+
await client.ecs.deleteSecurityGroup(instance.id);
|
|
340
|
+
break;
|
|
341
|
+
case 'ALIYUN_RAM_ROLE': {
|
|
342
|
+
const ramInstance = instance;
|
|
343
|
+
if (ramInstance.external)
|
|
344
|
+
break; // Skip external roles
|
|
345
|
+
const managedPolicies = ramInstance.managedPolicies;
|
|
346
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_RAM_ROLE', { id: instance.id }));
|
|
347
|
+
await client.ram.deleteRole(instance.id, managedPolicies);
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case 'ALIYUN_SLS_INDEX': {
|
|
351
|
+
const [projectName, logstoreName] = instance.id.split('/');
|
|
352
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: instance.id }));
|
|
353
|
+
await client.sls.deleteIndex(projectName, logstoreName);
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case 'ALIYUN_SLS_LOGSTORE': {
|
|
357
|
+
const [projectName, logstoreName] = instance.id.split('/');
|
|
358
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: instance.id }));
|
|
359
|
+
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case 'ALIYUN_SLS_PROJECT':
|
|
363
|
+
// Shared/legacy SLS projects are never deleted at resource level — the
|
|
364
|
+
// destroyer releases the shared project once unused (legacy orphans are
|
|
365
|
+
// manual cleanup, see issue #214).
|
|
366
|
+
break;
|
|
367
|
+
case 'ALIYUN_FC3_HTTP_TRIGGER':
|
|
368
|
+
// HTTP trigger deletion requires functionName which is not available here.
|
|
369
|
+
// It is handled directly in deleteResource before calling this function.
|
|
370
|
+
logger_1.logger.warn(`HTTP trigger '${instance.id}' should be deleted before reaching dependent resource cleanup`);
|
|
371
|
+
break;
|
|
372
|
+
case 'ALIYUN_FC3_CUSTOM_DOMAIN':
|
|
373
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: instance.id }));
|
|
374
|
+
await client.fc3.deleteCustomDomain(instance.id);
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
logger_1.logger.warn(lang_1.lang.__('UNKNOWN_RESOURCE_TYPE', { type: instance.type }));
|
|
367
378
|
}
|
|
368
379
|
}
|
|
369
380
|
};
|
|
@@ -373,8 +384,15 @@ const createResource = async (context, fn, state) => {
|
|
|
373
384
|
const logicalId = `functions.${fn.key}`;
|
|
374
385
|
const existingResourceState = (0, common_1.getResource)(state, logicalId);
|
|
375
386
|
const existingDependentInstances = (existingResourceState?.instances ?? []).filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION');
|
|
376
|
-
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances);
|
|
387
|
+
const dependentResources = await createDependentResources(context, fn, serviceName, existingDependentInstances, state);
|
|
388
|
+
const stateWithSharedProject = dependentResources.sharedProject
|
|
389
|
+
? (0, common_1.setSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY, dependentResources.sharedProject)
|
|
390
|
+
: state;
|
|
377
391
|
let config = (0, fc3Types_1.functionToFc3Config)(fn);
|
|
392
|
+
config = {
|
|
393
|
+
...config,
|
|
394
|
+
tags: [{ key: ownershipTag_1.OWNERSHIP_TAG_KEY, value: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) }],
|
|
395
|
+
};
|
|
378
396
|
if (dependentResources.logConfig) {
|
|
379
397
|
config = {
|
|
380
398
|
...config,
|
|
@@ -416,7 +434,7 @@ const createResource = async (context, fn, state) => {
|
|
|
416
434
|
};
|
|
417
435
|
}
|
|
418
436
|
const codePath = fn.code.path;
|
|
419
|
-
const codeHash = (0, common_1.
|
|
437
|
+
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
420
438
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
421
439
|
const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
422
440
|
const dependentInstances = dependentResources.instances.map((dep) => ({
|
|
@@ -436,7 +454,7 @@ const createResource = async (context, fn, state) => {
|
|
|
436
454
|
lastUpdated: new Date().toISOString(),
|
|
437
455
|
status: 'tainted',
|
|
438
456
|
};
|
|
439
|
-
const stateAfterDependents = (0, common_1.setResource)(
|
|
457
|
+
const stateAfterDependents = (0, common_1.setResource)(stateWithSharedProject, logicalId, taintedResourceState);
|
|
440
458
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
441
459
|
const isTainted = existingResourceState?.status === 'tainted';
|
|
442
460
|
const existingFunctionOnRetry = isTainted ? await client.fc3.getFunction(fn.name) : null;
|
|
@@ -454,12 +472,18 @@ const createResource = async (context, fn, state) => {
|
|
|
454
472
|
logger_1.logger.warn(`Create function returned recoverable error for ${fn.name}, reconciling with provider state: ${String(error)}`);
|
|
455
473
|
const functionAfterError = await client.fc3.getFunction(fn.name);
|
|
456
474
|
if (functionAfterError) {
|
|
475
|
+
if (functionAfterError.state === 'Failed') {
|
|
476
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`FC3 function ${fn.name} is in Failed state after create (reason: ${functionAfterError.stateReason ?? 'unknown'})`));
|
|
477
|
+
}
|
|
457
478
|
logger_1.logger.info(`Function ${fn.name} found after create error reconciliation, continuing deployment flow`);
|
|
458
479
|
}
|
|
459
480
|
else {
|
|
460
481
|
await delay(RECOVERY_GET_FUNCTION_DELAY_MS);
|
|
461
482
|
const functionAfterDelay = await client.fc3.getFunction(fn.name);
|
|
462
483
|
if (functionAfterDelay) {
|
|
484
|
+
if (functionAfterDelay.state === 'Failed') {
|
|
485
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`FC3 function ${fn.name} is in Failed state after create (reason: ${functionAfterDelay.stateReason ?? 'unknown'})`));
|
|
486
|
+
}
|
|
463
487
|
logger_1.logger.info(`Function ${fn.name} found after delayed reconciliation, continuing deployment flow`);
|
|
464
488
|
}
|
|
465
489
|
else {
|
|
@@ -467,21 +491,87 @@ const createResource = async (context, fn, state) => {
|
|
|
467
491
|
}
|
|
468
492
|
}
|
|
469
493
|
}
|
|
494
|
+
else if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['FunctionAlreadyExists'])) {
|
|
495
|
+
// Idempotent adoption: the function already exists in the provider.
|
|
496
|
+
// Adopt it ONLY if it carries our ownership tag (proves a previous run
|
|
497
|
+
// of THIS stack created it — e.g. state was reset). An untagged
|
|
498
|
+
// same-named function may belong to another project, so it must fail
|
|
499
|
+
// loudly rather than silently taking it over (destroy would then remove
|
|
500
|
+
// a resource that was never ours).
|
|
501
|
+
const probe = await client.fc3.getFunction(fn.name);
|
|
502
|
+
if (probe && (0, ownershipTag_1.isOwnedByStack)(context, logicalId, probe.tags)) {
|
|
503
|
+
logger_1.logger.info(`Function ${fn.name} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
throw new types_1.PartialResourceError(stateAfterDependents, 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 adopt — resolve manually.`));
|
|
507
|
+
}
|
|
508
|
+
}
|
|
470
509
|
else {
|
|
471
510
|
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
472
511
|
}
|
|
473
512
|
}
|
|
474
|
-
|
|
513
|
+
let functionInfo;
|
|
514
|
+
try {
|
|
515
|
+
functionInfo = await client.fc3.getFunction(fn.name);
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
519
|
+
}
|
|
475
520
|
if (!functionInfo) {
|
|
476
|
-
throw new Error(`Failed to refresh state for function: ${fn.name}`);
|
|
521
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`Failed to refresh state for function: ${fn.name}`));
|
|
522
|
+
}
|
|
523
|
+
if (functionInfo.state === 'Failed') {
|
|
524
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`FC3 function ${fn.name} is in Failed state (reason: ${functionInfo.stateReason ?? 'unknown'})`));
|
|
477
525
|
}
|
|
478
526
|
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
479
527
|
const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
|
|
528
|
+
const lifecycleInstances = [];
|
|
529
|
+
try {
|
|
530
|
+
if (fn.triggers?.http) {
|
|
531
|
+
const triggerConfig = buildHttpTriggerConfig(fn.triggers.http);
|
|
532
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
533
|
+
await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', triggerConfig);
|
|
534
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
535
|
+
lifecycleInstances.push({
|
|
536
|
+
type: 'ALIYUN_FC3_HTTP_TRIGGER',
|
|
537
|
+
id: 'http-trigger',
|
|
538
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-http-trigger', context.stage, fn.name),
|
|
539
|
+
attributes: { ...triggerConfig },
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
if (fn.domain) {
|
|
543
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: fn.domain.domain_name }));
|
|
544
|
+
let certConfig;
|
|
545
|
+
if (fn.domain.certificate_id) {
|
|
546
|
+
const certId = fn.domain.certificate_id;
|
|
547
|
+
const detail = await client.cas.getCertificate(certId);
|
|
548
|
+
if (!detail || !detail.cert || !detail.key) {
|
|
549
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: certId }));
|
|
550
|
+
}
|
|
551
|
+
certConfig = {
|
|
552
|
+
certName: `${context.service}-${context.stage}-fc3-domain`,
|
|
553
|
+
certificate: detail.cert,
|
|
554
|
+
privateKey: detail.key,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
await client.fc3.createCustomDomain(fn.domain.domain_name, fn.domain.protocol, fn.name, certConfig);
|
|
558
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: fn.domain.domain_name }));
|
|
559
|
+
lifecycleInstances.push({
|
|
560
|
+
type: 'ALIYUN_FC3_CUSTOM_DOMAIN',
|
|
561
|
+
id: fn.domain.domain_name,
|
|
562
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-custom-domain', context.stage, fn.domain.domain_name),
|
|
563
|
+
attributes: { protocol: fn.domain.protocol, certificate_id: fn.domain.certificate_id },
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
569
|
+
}
|
|
480
570
|
const resourceState = {
|
|
481
571
|
mode: 'managed',
|
|
482
572
|
region: context.region,
|
|
483
573
|
definition,
|
|
484
|
-
instances: [fcInstance, ...dependentInstances],
|
|
574
|
+
instances: [fcInstance, ...lifecycleInstances, ...dependentInstances],
|
|
485
575
|
lastUpdated: new Date().toISOString(),
|
|
486
576
|
status: 'ready',
|
|
487
577
|
};
|
|
@@ -499,27 +589,47 @@ const updateResource = async (context, fn, state) => {
|
|
|
499
589
|
const logicalId = `functions.${fn.key}`;
|
|
500
590
|
const existingState = (0, common_1.getResource)(state, logicalId);
|
|
501
591
|
const existingInstances = (existingState?.instances ?? []);
|
|
502
|
-
const hasSlsResources = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT'
|
|
592
|
+
const hasSlsResources = existingInstances.some((i) => i.type === 'ALIYUN_SLS_PROJECT' ||
|
|
593
|
+
i.type === 'ALIYUN_SLS_LOGSTORE' ||
|
|
594
|
+
i.type === 'ALIYUN_SLS_INDEX');
|
|
503
595
|
const hasRamRole = existingInstances.some((i) => i.type === 'ALIYUN_RAM_ROLE');
|
|
504
596
|
const hasSecurityGroup = existingInstances.some((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP');
|
|
505
597
|
const hasNasResources = existingInstances.some((i) => i.type === 'ALIYUN_NAS_FILE_SYSTEM');
|
|
506
598
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
507
599
|
const newDependentInstances = [];
|
|
508
600
|
let logConfig;
|
|
601
|
+
let sharedProjectState;
|
|
509
602
|
let role;
|
|
510
603
|
let securityGroup;
|
|
511
604
|
let nasConfig;
|
|
605
|
+
// SLS dependent-instance types to drop from the resulting state when
|
|
606
|
+
// function logging is disabled (true -> false).
|
|
607
|
+
const droppedSlsDependentTypes = [];
|
|
608
|
+
// Set when the shared project is released (deleted or gone) so its stale
|
|
609
|
+
// shared-state entry is removed from the returned state.
|
|
610
|
+
let releasedSharedProject = false;
|
|
512
611
|
if (fn.log && !hasSlsResources) {
|
|
513
|
-
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
612
|
+
const deps = await createDependentResources(context, { ...fn, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName, undefined, state);
|
|
514
613
|
logConfig = deps.logConfig;
|
|
515
614
|
newDependentInstances.push(...deps.instances.filter((i) => i.type.startsWith('ALIYUN_SLS_')));
|
|
615
|
+
if (deps.sharedProject) {
|
|
616
|
+
sharedProjectState = deps.sharedProject;
|
|
617
|
+
}
|
|
516
618
|
}
|
|
517
619
|
else if (hasSlsResources) {
|
|
518
|
-
const slsProjectInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_PROJECT');
|
|
519
620
|
const slsLogstoreInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
520
|
-
if (
|
|
521
|
-
|
|
522
|
-
|
|
621
|
+
if (fn.log) {
|
|
622
|
+
if (slsLogstoreInstance) {
|
|
623
|
+
const [projectName, logstoreName] = slsLogstoreInstance.id.split('/');
|
|
624
|
+
logConfig = { project: projectName, logstore: logstoreName };
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
// Logging disabled: the owned index + logstore are deleted from the
|
|
629
|
+
// provider after the function log config is cleared, and the SLS
|
|
630
|
+
// instances are dropped from state. The shared project is released by
|
|
631
|
+
// the destroyer once no logstores remain (issue #214).
|
|
632
|
+
droppedSlsDependentTypes.push('ALIYUN_SLS_INDEX', 'ALIYUN_SLS_LOGSTORE', 'ALIYUN_SLS_PROJECT');
|
|
523
633
|
}
|
|
524
634
|
}
|
|
525
635
|
const newIamRole = fn.iam?.role;
|
|
@@ -528,7 +638,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
528
638
|
role = { roleName: '', arn: newIamRole };
|
|
529
639
|
}
|
|
530
640
|
else if (!hasRamRole) {
|
|
531
|
-
const deps = await createDependentResources(context, { ...fn, log: false, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
641
|
+
const deps = await createDependentResources(context, { ...fn, log: false, network: undefined, storage: { ...fn.storage, nas: undefined } }, serviceName, undefined, state);
|
|
532
642
|
role = deps.role;
|
|
533
643
|
newDependentInstances.push(...deps.instances.filter((i) => i.type === 'ALIYUN_RAM_ROLE'));
|
|
534
644
|
}
|
|
@@ -568,7 +678,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
568
678
|
}
|
|
569
679
|
}
|
|
570
680
|
if (fn.network && !hasSecurityGroup) {
|
|
571
|
-
const deps = await createDependentResources(context, { ...fn, log: false, storage: { ...fn.storage, nas: undefined } }, serviceName);
|
|
681
|
+
const deps = await createDependentResources(context, { ...fn, log: false, storage: { ...fn.storage, nas: undefined } }, serviceName, undefined, state);
|
|
572
682
|
securityGroup = deps.securityGroup;
|
|
573
683
|
newDependentInstances.push(...deps.instances.filter((i) => i.type === 'ALIYUN_ECS_SECURITY_GROUP'));
|
|
574
684
|
}
|
|
@@ -579,7 +689,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
579
689
|
}
|
|
580
690
|
}
|
|
581
691
|
if (fn.storage?.nas && fn.storage.nas.length > 0 && fn.network && !hasNasResources) {
|
|
582
|
-
const deps = await createDependentResources(context, { ...fn, log: false }, serviceName);
|
|
692
|
+
const deps = await createDependentResources(context, { ...fn, log: false }, serviceName, undefined, state);
|
|
583
693
|
nasConfig = deps.nasConfig;
|
|
584
694
|
newDependentInstances.push(...deps.instances.filter((i) => i.type.startsWith('ALIYUN_NAS_')));
|
|
585
695
|
}
|
|
@@ -635,7 +745,7 @@ const updateResource = async (context, fn, state) => {
|
|
|
635
745
|
}
|
|
636
746
|
const codePath = fn.code.path;
|
|
637
747
|
const currentCodeHash = existingState?.definition?.codeHash;
|
|
638
|
-
const desiredCodeHash = (0, common_1.
|
|
748
|
+
const desiredCodeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
639
749
|
const codeChanged = currentCodeHash !== desiredCodeHash;
|
|
640
750
|
const existingConfig = existingState?.definition;
|
|
641
751
|
const desiredDefinition = (0, fc3Types_1.extractFc3Definition)(config, desiredCodeHash);
|
|
@@ -649,21 +759,177 @@ const updateResource = async (context, fn, state) => {
|
|
|
649
759
|
const ossCode = await ensureOssCodeUpload(client, codePath, context.region, fn.name);
|
|
650
760
|
await client.fc3.updateFunctionCode(fn.name, codePath, ossCode);
|
|
651
761
|
}
|
|
762
|
+
if (droppedSlsDependentTypes.length > 0) {
|
|
763
|
+
const slsLogstoreInstance = existingInstances.find((i) => i.type === 'ALIYUN_SLS_LOGSTORE');
|
|
764
|
+
if (slsLogstoreInstance) {
|
|
765
|
+
const [projectName, logstoreName] = slsLogstoreInstance.id.split('/');
|
|
766
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_INDEX', { id: `${projectName}/${logstoreName}` }));
|
|
767
|
+
try {
|
|
768
|
+
await client.sls.deleteIndex(projectName, logstoreName);
|
|
769
|
+
}
|
|
770
|
+
catch {
|
|
771
|
+
// index already gone — best-effort
|
|
772
|
+
}
|
|
773
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_SLS_LOGSTORE', { id: `${projectName}/${logstoreName}` }));
|
|
774
|
+
try {
|
|
775
|
+
await client.sls.deleteLogstore(projectName, logstoreName);
|
|
776
|
+
}
|
|
777
|
+
catch {
|
|
778
|
+
// logstore already gone — best-effort
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
// Release the shared project once no logstores remain in the provider; it
|
|
782
|
+
// is retained (with its state entry) while another service or the gateway
|
|
783
|
+
// still references it.
|
|
784
|
+
const shared = (0, common_1.getSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
785
|
+
if (shared) {
|
|
786
|
+
const releaseResult = await (0, sharedLogProject_1.releaseSharedSlsProjectIfUnused)(context, client, shared);
|
|
787
|
+
if (releaseResult !== 'retained') {
|
|
788
|
+
releasedSharedProject = true;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
652
792
|
if (!configChanged && !codeChanged) {
|
|
653
793
|
logger_1.logger.warn(lang_1.lang.__('UPDATING_RESOURCE_WITH_NO_CHANGES', { resourceType: 'function', name: fn.name }));
|
|
654
794
|
}
|
|
795
|
+
const existingHttpTrigger = existingInstances.find((i) => i.type === 'ALIYUN_FC3_HTTP_TRIGGER');
|
|
796
|
+
const desiredHttpTrigger = fn.triggers?.http;
|
|
797
|
+
if (desiredHttpTrigger && !existingHttpTrigger) {
|
|
798
|
+
const triggerConfig = buildHttpTriggerConfig(desiredHttpTrigger);
|
|
799
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
800
|
+
await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', triggerConfig);
|
|
801
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
802
|
+
}
|
|
803
|
+
else if (!desiredHttpTrigger && existingHttpTrigger) {
|
|
804
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
805
|
+
try {
|
|
806
|
+
await client.fc3.deleteTrigger(fn.name, 'http-trigger');
|
|
807
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: 'http-trigger' }));
|
|
808
|
+
}
|
|
809
|
+
catch (err) {
|
|
810
|
+
const errorCode = err?.code;
|
|
811
|
+
if (errorCode !== 'TriggerNotFound')
|
|
812
|
+
throw err;
|
|
813
|
+
logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: 'http-trigger' }));
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
else if (desiredHttpTrigger && existingHttpTrigger) {
|
|
817
|
+
const desiredTriggerConfig = buildHttpTriggerConfig(desiredHttpTrigger);
|
|
818
|
+
const existingAttrs = existingHttpTrigger.attributes ?? {};
|
|
819
|
+
if (!(0, common_1.attributesEqual)(desiredTriggerConfig, existingAttrs)) {
|
|
820
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_HTTP_TRIGGER', { functionName: fn.name }));
|
|
821
|
+
try {
|
|
822
|
+
await client.fc3.deleteTrigger(fn.name, 'http-trigger');
|
|
823
|
+
}
|
|
824
|
+
catch (err) {
|
|
825
|
+
const errorCode = err?.code;
|
|
826
|
+
if (errorCode !== 'TriggerNotFound')
|
|
827
|
+
throw err;
|
|
828
|
+
}
|
|
829
|
+
await client.fc3.createTrigger(fn.name, 'http-trigger', 'http', desiredTriggerConfig);
|
|
830
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_CREATED', { triggerName: 'http-trigger', functionName: fn.name }));
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
const existingCustomDomain = existingInstances.find((i) => i.type === 'ALIYUN_FC3_CUSTOM_DOMAIN');
|
|
834
|
+
const desiredDomain = fn.domain;
|
|
835
|
+
if (desiredDomain && !existingCustomDomain) {
|
|
836
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CUSTOM_DOMAIN', { domainName: desiredDomain.domain_name }));
|
|
837
|
+
let certConfig;
|
|
838
|
+
if (desiredDomain.certificate_id) {
|
|
839
|
+
const certId = desiredDomain.certificate_id;
|
|
840
|
+
const detail = await client.cas.getCertificate(certId);
|
|
841
|
+
if (!detail || !detail.cert || !detail.key) {
|
|
842
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: certId }));
|
|
843
|
+
}
|
|
844
|
+
certConfig = {
|
|
845
|
+
certName: `${context.service}-${context.stage}-fc3-domain`,
|
|
846
|
+
certificate: detail.cert,
|
|
847
|
+
privateKey: detail.key,
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
await client.fc3.createCustomDomain(desiredDomain.domain_name, desiredDomain.protocol, fn.name, certConfig);
|
|
851
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: desiredDomain.domain_name }));
|
|
852
|
+
}
|
|
853
|
+
else if (!desiredDomain && existingCustomDomain) {
|
|
854
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: existingCustomDomain.id }));
|
|
855
|
+
try {
|
|
856
|
+
await client.fc3.deleteCustomDomain(existingCustomDomain.id);
|
|
857
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: existingCustomDomain.id }));
|
|
858
|
+
}
|
|
859
|
+
catch (err) {
|
|
860
|
+
const errorCode = err?.code;
|
|
861
|
+
if (errorCode !== 'CustomDomainNotFound')
|
|
862
|
+
throw err;
|
|
863
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
864
|
+
resourceType: 'Custom Domain',
|
|
865
|
+
name: existingCustomDomain.id,
|
|
866
|
+
}));
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
else if (desiredDomain && existingCustomDomain) {
|
|
870
|
+
const existingProtocol = existingCustomDomain.attributes?.protocol;
|
|
871
|
+
const domainChanged = desiredDomain.domain_name !== existingCustomDomain.id ||
|
|
872
|
+
desiredDomain.protocol !== existingProtocol;
|
|
873
|
+
if (domainChanged) {
|
|
874
|
+
logger_1.logger.info(lang_1.lang.__('UPDATING_CUSTOM_DOMAIN', { domainName: desiredDomain.domain_name }));
|
|
875
|
+
let certConfig;
|
|
876
|
+
if (desiredDomain.certificate_id) {
|
|
877
|
+
const certId = desiredDomain.certificate_id;
|
|
878
|
+
const detail = await client.cas.getCertificate(certId);
|
|
879
|
+
if (!detail || !detail.cert || !detail.key) {
|
|
880
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: certId }));
|
|
881
|
+
}
|
|
882
|
+
certConfig = {
|
|
883
|
+
certName: `${context.service}-${context.stage}-fc3-domain`,
|
|
884
|
+
certificate: detail.cert,
|
|
885
|
+
privateKey: detail.key,
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
try {
|
|
889
|
+
await client.fc3.deleteCustomDomain(existingCustomDomain.id);
|
|
890
|
+
}
|
|
891
|
+
catch (err) {
|
|
892
|
+
const errorCode = err?.code;
|
|
893
|
+
if (errorCode !== 'CustomDomainNotFound')
|
|
894
|
+
throw err;
|
|
895
|
+
}
|
|
896
|
+
await client.fc3.createCustomDomain(desiredDomain.domain_name, desiredDomain.protocol, fn.name, certConfig);
|
|
897
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_CREATED', { domainName: desiredDomain.domain_name }));
|
|
898
|
+
}
|
|
899
|
+
}
|
|
655
900
|
const functionInfo = await client.fc3.getFunction(fn.name);
|
|
656
901
|
if (!functionInfo) {
|
|
657
902
|
throw new Error(`Failed to refresh state for function: ${fn.name}`);
|
|
658
903
|
}
|
|
659
|
-
const codeHash = (0, common_1.
|
|
904
|
+
const codeHash = await (0, common_1.computeZipContentHash)(codePath);
|
|
660
905
|
const baseDefinition = (0, fc3Types_1.extractFc3Definition)(config, codeHash);
|
|
661
906
|
const definition = fn.iam ? { ...baseDefinition, iam: fn.iam } : baseDefinition;
|
|
662
907
|
const sid = (0, common_1.buildSid)('aliyun', 'fc3', context.stage, fn.name);
|
|
663
908
|
const fcInstance = buildFc3InstanceFromProvider(functionInfo, sid);
|
|
909
|
+
const lifecycleInstances = [];
|
|
910
|
+
if (fn.triggers?.http) {
|
|
911
|
+
const triggerConfig = buildHttpTriggerConfig(fn.triggers.http);
|
|
912
|
+
lifecycleInstances.push({
|
|
913
|
+
type: 'ALIYUN_FC3_HTTP_TRIGGER',
|
|
914
|
+
id: 'http-trigger',
|
|
915
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-http-trigger', context.stage, fn.name),
|
|
916
|
+
attributes: { ...triggerConfig },
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
if (fn.domain) {
|
|
920
|
+
lifecycleInstances.push({
|
|
921
|
+
type: 'ALIYUN_FC3_CUSTOM_DOMAIN',
|
|
922
|
+
id: fn.domain.domain_name,
|
|
923
|
+
sid: (0, common_1.buildSid)('aliyun', 'fc3-custom-domain', context.stage, fn.domain.domain_name),
|
|
924
|
+
attributes: { protocol: fn.domain.protocol },
|
|
925
|
+
});
|
|
926
|
+
}
|
|
664
927
|
const existingDependentInstances = existingInstances
|
|
665
928
|
.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION')
|
|
929
|
+
.filter((i) => i.type !== 'ALIYUN_FC3_HTTP_TRIGGER')
|
|
930
|
+
.filter((i) => i.type !== 'ALIYUN_FC3_CUSTOM_DOMAIN')
|
|
666
931
|
.filter((i) => !(typeof fn.iam?.role === 'string' && i.type === 'ALIYUN_RAM_ROLE'))
|
|
932
|
+
.filter((i) => !droppedSlsDependentTypes.includes(i.type))
|
|
667
933
|
.map((i) => {
|
|
668
934
|
const { sid: existingSid, id: existingId, ...rest } = i;
|
|
669
935
|
return {
|
|
@@ -686,17 +952,70 @@ const updateResource = async (context, fn, state) => {
|
|
|
686
952
|
mode: 'managed',
|
|
687
953
|
region: context.region,
|
|
688
954
|
definition,
|
|
689
|
-
instances: [
|
|
955
|
+
instances: [
|
|
956
|
+
fcInstance,
|
|
957
|
+
...lifecycleInstances,
|
|
958
|
+
...existingDependentInstances,
|
|
959
|
+
...newDependentInstancesMapped,
|
|
960
|
+
],
|
|
690
961
|
lastUpdated: new Date().toISOString(),
|
|
691
962
|
};
|
|
692
|
-
|
|
963
|
+
let finalState;
|
|
964
|
+
if (sharedProjectState) {
|
|
965
|
+
finalState = (0, common_1.setSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY, sharedProjectState);
|
|
966
|
+
}
|
|
967
|
+
else if (releasedSharedProject) {
|
|
968
|
+
finalState = (0, common_1.removeSharedResource)(state, context.stage, sharedLogProject_1.SHARED_LOG_PROJECT_KEY);
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
finalState = state;
|
|
972
|
+
}
|
|
973
|
+
return (0, common_1.setResource)(finalState, logicalId, resourceState);
|
|
693
974
|
};
|
|
694
975
|
exports.updateResource = updateResource;
|
|
695
976
|
const deleteResource = async (context, functionName, logicalId, state) => {
|
|
696
977
|
const existingState = (0, common_1.getResource)(state, logicalId);
|
|
697
978
|
const existingInstances = (existingState?.instances ?? []);
|
|
698
|
-
const hasFcFunction = existingInstances.some((i) => i.type === 'ALIYUN_FC3_FUNCTION');
|
|
699
979
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
980
|
+
// Delete HTTP trigger and custom domain before function (they depend on it)
|
|
981
|
+
const httpTriggerInstance = existingInstances.find((i) => i.type === 'ALIYUN_FC3_HTTP_TRIGGER');
|
|
982
|
+
if (httpTriggerInstance) {
|
|
983
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_HTTP_TRIGGER', { triggerName: httpTriggerInstance.id, functionName }));
|
|
984
|
+
try {
|
|
985
|
+
await client.fc3.deleteTrigger(functionName, httpTriggerInstance.id);
|
|
986
|
+
logger_1.logger.info(lang_1.lang.__('HTTP_TRIGGER_DELETED', { triggerName: httpTriggerInstance.id }));
|
|
987
|
+
}
|
|
988
|
+
catch (err) {
|
|
989
|
+
const errorCode = err?.code;
|
|
990
|
+
if (errorCode === 'TriggerNotFound') {
|
|
991
|
+
logger_1.logger.warn(lang_1.lang.__('HTTP_TRIGGER_NOT_FOUND', { triggerName: httpTriggerInstance.id }));
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
throw err;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const customDomainInstance = existingInstances.find((i) => i.type === 'ALIYUN_FC3_CUSTOM_DOMAIN');
|
|
999
|
+
if (customDomainInstance) {
|
|
1000
|
+
logger_1.logger.info(lang_1.lang.__('DELETING_CUSTOM_DOMAIN', { domainName: customDomainInstance.id }));
|
|
1001
|
+
try {
|
|
1002
|
+
await client.fc3.deleteCustomDomain(customDomainInstance.id);
|
|
1003
|
+
logger_1.logger.info(lang_1.lang.__('CUSTOM_DOMAIN_DELETED', { domainName: customDomainInstance.id }));
|
|
1004
|
+
}
|
|
1005
|
+
catch (err) {
|
|
1006
|
+
const errorCode = err?.code;
|
|
1007
|
+
if (errorCode === 'CustomDomainNotFound') {
|
|
1008
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
1009
|
+
resourceType: 'Custom Domain',
|
|
1010
|
+
name: customDomainInstance.id,
|
|
1011
|
+
}));
|
|
1012
|
+
}
|
|
1013
|
+
else {
|
|
1014
|
+
throw err;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
const hasFcFunction = existingInstances.some((i) => i.type === 'ALIYUN_FC3_FUNCTION');
|
|
700
1019
|
if (hasFcFunction) {
|
|
701
1020
|
try {
|
|
702
1021
|
await client.fc3.deleteFunction(functionName);
|
|
@@ -711,7 +1030,10 @@ const deleteResource = async (context, functionName, logicalId, state) => {
|
|
|
711
1030
|
}
|
|
712
1031
|
}
|
|
713
1032
|
}
|
|
714
|
-
const dependentInstances = existingInstances.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION' &&
|
|
1033
|
+
const dependentInstances = existingInstances.filter((i) => i.type !== 'ALIYUN_FC3_FUNCTION' &&
|
|
1034
|
+
i.type !== 'ALIYUN_FC3_HTTP_TRIGGER' &&
|
|
1035
|
+
i.type !== 'ALIYUN_FC3_CUSTOM_DOMAIN' &&
|
|
1036
|
+
!i.type.includes('undefined'));
|
|
715
1037
|
if (dependentInstances.length > 0) {
|
|
716
1038
|
await deleteDependentResources(context, dependentInstances);
|
|
717
1039
|
}
|