简体   繁体   中英

Azure Resource Manager Query with multiple dynamic tag filters

I'm trying to query the Azure Cost Management API and I want to be able to filter the results based off of 2 different types of resource tags but I am having trouble figuring out the format. I can get the single tag filter working, but I'm blanking on the format for multiple. Can anyone throw in their 2 cents?

Working single filter query:

{
    "type": "Usage",
    "timeframe": "{TimeFrame}",
    "dataset": {
        "granularity": "None",
        "filter": {
            "tags": {
                    "name": "Environment",
                    "operator": "In",
                    "values": [
                        {Environment}
                    ]
                }
        },
        "aggregation": {
            "totalCost": {
                "name": "PreTaxCost",
                "function": "Sum"
            }
        },
        "grouping": [
            {
                "type": "Dimension",
                "name": "{Aggregation}"
            }
        ]
    }
}

My attempt at adding more than one filter:

{
    "type": "Usage",
    "timeframe": "{TimeFrame}",
    "dataset": {
        "granularity": "None",
        "filter": {
            "tags": [
                {
                    "name": "Environment",
                    "operator": "In",
                    "values": [
                        {Environment}
                    ]
                },
                {
                    "name": "Location",
                    "operator": "In",
                    "values": [
                        {Location}
                    ]
                }
            ]
        },
        "aggregation": {
            "totalCost": {
                "name": "PreTaxCost",
                "function": "Sum"
            }
        },
        "grouping": [
            {
                "type": "Dimension",
                "name": "{Aggregation}"
            }
        ]
    }
}

I am very new to Azure so please don't roast me too hard lol.

Thank you to everyone who took a look at my question, much appreciated even if you don't have an answer for me.

There was an issue with the way my parameters were set causing a bad query. Here is the working code with multiple tag attributes for filtering:

{
"type": "Usage",
"timeframe": "{TimeFrame}",
"dataset": {
    "granularity": "None",
    "filter": {
        "and": [
            {
                "tags": {
                    "name": "Location",
                    "operator": "In",
                    "values": [{LocationTag}]
                }
            },
            {
                "tags": {
                    "name": "Environment",
                    "operator": "In",
                    "Values": [{EnvironmentTag}]
                }
            },
            {
                "tags": {
                    "name": "Integrated-System",
                    "operator": "In",
                    "Values": [{IntegratedSystemTag}]
                }
            }
        ]
    },
    "aggregation": {
        "totalCost": {
            "name": "PreTaxCost",
            "function": "Sum"
        }
    },
    "grouping": [
        {
            "type": "Dimension",
            "name": "{Aggregation}"
        }
    ]
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM