mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
29 lines
963 B
JavaScript
29 lines
963 B
JavaScript
'use strict';
|
|
|
|
const ServerlessError = require('../../../serverless-error');
|
|
|
|
async function resolveCfRefValue(provider, resourceLogicalId, sdkParams = {}) {
|
|
return provider
|
|
.request(
|
|
'CloudFormation',
|
|
'listStackResources',
|
|
Object.assign(sdkParams, { StackName: provider.naming.getStackName() })
|
|
)
|
|
.then((result) => {
|
|
const targetStackResource = result.StackResourceSummaries.find(
|
|
(stackResource) => stackResource.LogicalResourceId === resourceLogicalId
|
|
);
|
|
if (targetStackResource) return targetStackResource.PhysicalResourceId;
|
|
if (result.NextToken) {
|
|
return resolveCfRefValue(provider, resourceLogicalId, { NextToken: result.NextToken });
|
|
}
|
|
|
|
throw new ServerlessError(
|
|
`Could not resolve Ref with name ${resourceLogicalId}. Are you sure this value matches one resource logical ID ?`,
|
|
'CF_REF_RESOLUTION'
|
|
);
|
|
});
|
|
}
|
|
|
|
module.exports = resolveCfRefValue;
|