mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
28 lines
937 B
JavaScript
28 lines
937 B
JavaScript
'use strict';
|
|
|
|
const ServerlessError = require('../../../classes/Error').ServerlessError;
|
|
|
|
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 ?`
|
|
);
|
|
});
|
|
}
|
|
|
|
module.exports = resolveCfRefValue;
|