async function ensureCiExists()

in tasks/Node/src/tasks/AzureDtlDeleteCustomImage/task.ts [10:29]


async function ensureCiExists(dtlClient: DevTestLabsClient, ciId: string): Promise<void> {
    const labName: string = resutil.getLabResourceName(ciId, 'labs');
    const labRgName: string = resutil.getLabResourceName(ciId, 'resourcegroups');
    const ciName: string = resutil.getLabResourceName(ciId, 'customimages');

    console.log(`Determining if Custom Image '${ciName}' exists in Lab '${labName}' under Resource Group '${labRgName}'.`);

    const customImages = await dtlClient.customImages.list(labRgName, labName);

    const ciExists = customImages && customImages.some((ci) => ci && ci.name && equalsIgnoreCase(ci.name, ciName));

    const message: string = `Lab Custom Image '${ciName}' ${ciExists ? 'exists' : 'does not exist'}.`;

    if (ciExists) {
        console.log(message);
    }
    else {
        throw message;
    }
}