class AzureCloudResourceService {

    public List<CloudResource> getInstanceCloudResources(String stackName, List<CloudResource> cloudResourceList, List<Group> groups,
            String resourceGroupName) {

        List<CloudResource> vmResourceList = new ArrayList<>();
        cloudResourceList
                .stream()
                .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AZURE_INSTANCE))
                .forEach(instance -> groups
                        .stream()
                        .map(Group::getInstances)
                        .forEach(cloudInstances -> cloudInstances
                                .stream()
                                .filter(cloudInstance -> cloudInstance.getTemplate().getStatus().equals(InstanceStatus.CREATE_REQUESTED))
                                .filter(cloudInstance -> instance.getName().equalsIgnoreCase(
                                        azureUtils.getPrivateInstanceId(stackName,
                                                cloudInstance.getTemplate().getGroupName(),
                                                Long.toString(cloudInstance.getTemplate().getPrivateId()))))
                                .peek(cloudInstance -> LOGGER.debug("The following resource is categorized as VM instance {}", cloudInstance.toString()))
                                .forEach(filteredInstance ->
                                        vmResourceList.add(buildVm(instance, filteredInstance.getTemplate().getGroupName(), resourceGroupName))
                                )
                        )
                );
        if (vmResourceList.size() == 0) {
            String message = String.format("No VM resource found amongst cloud resources: %s", cloudResourceList.toString());
            LOGGER.warn(message);
            throw new CloudbreakServiceException(message);
        }
        return vmResourceList;
    }

}