Ex.2 case: Project

{
    "resource_type": "identity.Project",
    "query": {
        "aggregate": {
            "group": {
                "keys": [
                    {
                        "key": "project_id",
                        "name": "project_id"
                    },
                    {
                        "key": "name",
                        "name": "project_name"
                    }
                ],
                "fields": [
                    {
                        "operator": "count",
                        "name": "project_count"
                    },
                    {
                        "key": "project_id",
                        "name": "selected_id",
                        "operator": "add_to_set"
                    }
                ]
            }
        },
        "filter": [
            {
                "key": "name",
                "value": [
                    "project",
                    "alters"
                ],
                "operator": "not_in"
            }
        ],
        "filter_or": [
            {
                "key": "name",
                "value": [
                    "stark",
                    "admin"
                ],
                "operator": "in"
            },
            {
                "key": "project_id",
                "value": [
                    "ua-abcdefg"
                ],
                "operator": "not_in"
            }
        ],
        "sort": {
            "name": "project_name",
            "desc": false
        },
        "limit": 3
    },
    "join": [
        {
            "keys": ["project_id"],
            "join_key": "outer",
            "resource_type": "inventory.Server",
            "query": {
                "aggregate": {
                    "group": {
                        "keys": [
                            {
                                "key": "project_id",
                                "name": "project_id"
                            }
                        ],
                        "fields": [
                            {
                                "operator": "count",
                                "name": "server_count"
                            }
                        ]
                    }
                }
            }
        },
        {
            "keys": [
                "service_account_id"
            ],
            "resource_type": "inventory.CloudService",
            "query": {
                "aggregate": {
                    "unwind": [
                        {
                            "path": "collection_info.service_accounts"
                        }
                    ],
                    "group": {
                        "keys": [
                            {
                                "key": "project_id",
                                "name": "service_account_id"
                            }
                        ],
                        "fields": [
                            {
                                "operator": "count",
                                "name": "cloud_service_count"
                            }
                        ]
                    }
                }
            }
        },
        {
            "keys": ["project_id"],
            "join_key": "outer",
            "resource_type": "inventory.CloudService",
            "query": {
                "aggregate": {
                    "group": {
                        "keys": [
                            {
                                "key": "project_id",
                                "name": "project_id"
                            }
                        ],
                        "fields": [
                            {
                                "operator": "count",
                                "name": "cloud_service_count"
                            }
                        ]
                    }
                }
            }
        }
    ],
    "formulas": [
        {
            "name": "resource_count",
            "formula": "server_count + cloud_service_count"
        }
    ]
}

Last updated