mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
30 lines
969 B
JavaScript
30 lines
969 B
JavaScript
import ServerlessError from '../../../serverless-error.js'
|
|
|
|
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',
|
|
)
|
|
})
|
|
}
|
|
|
|
export default resolveCfRefValue
|