You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/governance/resource-graph/tutorials/create-share-query.md
+84-38Lines changed: 84 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,14 @@ ms.service: resource-graph
9
9
---
10
10
# Tutorial: Create and share an Azure Resource Graph query in the Azure portal
11
11
12
-
Azure Resource Graph Explorer lets you save your Resource Graph queries directly in the Azure portal. There are two types of queries: _Private_ and _Shared_. A Private query is saved in your Azure portal settings. Whereas a Shared query is a Resource Manager resource that can be managed with role-based
13
-
access controls (RBAC) and protected with resource locks.
12
+
Azure Resource Graph Explorer lets you save your Resource Graph queries directly in the Azure
13
+
portal. There are two types of queries: _Private_ and _Shared_. A Private query is saved in your
14
+
Azure portal settings. Whereas a Shared query is a Resource Manager resource that can be managed
15
+
with role-based access controls (RBAC) and protected with resource locks.
14
16
15
-
By saving queries in the Azure portal, you save the time you might otherwise spend looking for your favorite or commonly used queries. When you share queries, you help your team realize goals of consistency and efficiency through repetition.
17
+
By saving queries in the Azure portal, you save the time you might otherwise spend looking for your
18
+
favorite or commonly used queries. When you share queries, you help your team realize goals of
19
+
consistency and efficiency through repetition.
16
20
17
21
In this tutorial, you'll complete the following tasks:
18
22
@@ -24,13 +28,18 @@ In this tutorial, you'll complete the following tasks:
24
28
25
29
## Prerequisites
26
30
27
-
To complete this tutorial, you need an Azure subscription. If you don't have one, create a [free account](https://azure.microsoft.com/free/) before you begin.
31
+
To complete this tutorial, you need an Azure subscription. If you don't have one, create a
32
+
[free account](https://azure.microsoft.com/free/) before you begin.
28
33
29
34
## Create and delete a Private query
30
35
31
-
Private queries are accessible and visible only to the account that creates them. As they're saved in an account's Azure portal settings, they can be created, used, and deleted only from inside the Azure portal. A Private query isn't a Resource Manager resource. To create a new Private query, follow these steps:
36
+
Private queries are accessible and visible only to the account that creates them. As they're saved
37
+
in an account's Azure portal settings, they can be created, used, and deleted only from inside the
38
+
Azure portal. A Private query isn't a Resource Manager resource. To create a new Private query,
39
+
follow these steps:
32
40
33
-
1. From the portal menu, select **All services** or use the Azure search box at the top of all pages. Search for and then select **Resource Graph Explorer**.
41
+
1. From the portal menu, select **All services** or use the Azure search box at the top of all
42
+
pages. Search for and then select **Resource Graph Explorer**.
34
43
35
44
1. On the **Query 1** tab on the Azure Resource Graph Explorer page, enter the following query:
36
45
@@ -46,26 +55,35 @@ Private queries are accessible and visible only to the account that creates them
46
55
[Samples – Count virtual machines by OS type](../samples/starter.md#count-virtual-machines-by-os-type).
47
56
48
57
49
-
1. Select **Save** or **Save as**, enter **Count VMs by OS** as the name, leave the type as **Private
50
-
query**, and then select **Save** at the bottom of the **Save query** pane. The tab title changes from **Query 1** to **Count VMs by OS**.
58
+
1. Select **Save** or **Save as**, enter **Count VMs by OS** as the name, leave the type as
59
+
**Private query**, and then select **Save** at the bottom of the **Save query** pane. The tab
60
+
title changes from **Query 1** to **Count VMs by OS**.
51
61
52
-
1. Move away from Azure Resource Graph Explorer in the Azure portal and then return to it. Notice that the saved query is no longer displayed and the **Query 1** tab has returned.
62
+
1. Move away from Azure Resource Graph Explorer in the Azure portal and then return to it. Notice
63
+
that the saved query is no longer displayed and the **Query 1** tab has returned.
53
64
54
-
1. Select **Open a query**. Make sure that the type is **Private query**. The saved name **Count VMs by OS** now
55
-
appears in the **Query Name** list. When you select the title link of the saved query, it's loaded into a
56
-
new tab with that query's name.
65
+
1. Select **Open a query**. Make sure that the type is **Private query**. The saved name **Count VMs
66
+
by OS** now appears in the **Query Name** list. When you select the title link of the saved
67
+
query, it's loaded into a new tab with that query's name.
57
68
58
-
> [!NOTE]
59
-
> When a saved query is open and the tab shows its name, selecting the **Save** button updates it with any changes that have been made. To create a new saved query from this open query, select **Save as** and proceed as if you were saving a brand new query.
69
+
> [!NOTE] When a saved query is open and the tab shows its name, selecting the **Save** button
70
+
> updates it with any changes that have been made. To create a new saved query from this open
71
+
> query, select **Save as** and proceed as if you were saving a brand new query.
60
72
61
-
1. To delete the saved query, select **Open a query** again, and verify that the **Type** field is set to **Private
62
-
query**. On the row of the saved `Count VMs by OS` query, select **Delete** (Recycle bin icon). In the confirmation dialog box, select **Yes** to finish deleting the query. Then, close the **Open a query** pane.
73
+
1. To delete the saved query, select **Open a query** again, and verify that the **Type** field is
74
+
set to **Private query**. On the row of the saved `Count VMs by OS` query, select **Delete**
75
+
(Recycle bin icon). In the confirmation dialog box, select **Yes** to finish deleting the query.
76
+
Then, close the **Open a query** pane.
63
77
64
78
## Create a Shared query
65
79
66
-
Unlike a Private query, a Shared query is a Resource Manager resource. This fact means the query gets saved to a resource group, can be managed and controlled with RBAC, and can even be protected with resource locks. As a resource, anyone who has the appropriate permissions can see and use it. To create a new Shared query, follow these steps:
80
+
Unlike a Private query, a Shared query is a Resource Manager resource. This fact means the query
81
+
gets saved to a resource group, can be managed and controlled with RBAC, and can even be protected
82
+
with resource locks. As a resource, anyone who has the appropriate permissions can see and use it.
83
+
To create a new Shared query, follow these steps:
67
84
68
-
1. From the portal menu, select **All services**, or use the Azure search box at the top of all pages to search for and select **Resource Graph Explorer**.
85
+
1. From the portal menu, select **All services**, or use the Azure search box at the top of all
86
+
pages to search for and select **Resource Graph Explorer**.
69
87
70
88
1. On the **Query 1** tab on the Azure Resource Graph Explorer page, enter the following query:
71
89
@@ -78,31 +96,45 @@ Unlike a Private query, a Shared query is a Resource Manager resource. This fact
78
96
Select **Run query** to see the query results in the bottom pane.
79
97
80
98
For more information about this query, see
81
-
[Samples – Count virtual machines by OS type](../samples/starter.md#count-virtual-machines-by-os-type).
99
+
[Samples – Count virtual machines by OS type](../samples/starter.md#count-virtual-machines-by-os-type).
82
100
83
101
1. Select **Save** or **Save as**.
84
102
103
+
85
104

86
105
87
-
1. In the **Save query** pane, enter **Count VMs by OS** for the name.
88
-
1. Change the type to **Shared query**, set the description to **Count of virtual machines by OS type**, and set **Subscription** to specify where the query resource gets created.
89
-
1. Leave the **Publish to resource-graph-queries resource group** check box selected and the **Resource Group location** set to **(US) West Central US**.
90
-
1. Select
91
-
**Save** at the bottom of the **Save query** pane. The tab title changes from **Query 1** to **Count VMs by OS**. The first time the **resource-graph-queries** resource group is used, the save takes longer than expected as the resource group gets created.
106
+
1. In the **Save query** pane, enter **Count VMs by OS** for the name.
107
+
1. Change the type to **Shared query**, set the description to **Count of virtual machines by OS
108
+
type**, and set **Subscription** to specify where the query resource gets created.
109
+
1. Leave the **Publish to resource-graph-queries resource group** check box selected and the
110
+
**Resource Group location** set to **(US) West Central US**.
111
+
1. Select **Save** at the bottom of the **Save query** pane. The tab title changes from **Query 1**
112
+
to **Count VMs by OS**. The first time the **resource-graph-queries** resource group is used, the
113
+
save takes longer than expected as the resource group gets created.
92
114
115
+
93
116

94
117
95
-
> [!NOTE]
96
-
> You can clear the **Publish to resource-graph-queries resource group** check box if you want to provide the name of an existing resource group to save the shared query into. Using the default named resource group for queries makes Shared queries easier to discover. It also makes the purpose of that resource group more apparent. However, you might opt to select an existing resource group for security reasons based on existing permissions.
118
+
> [!NOTE] You can clear the **Publish to resource-graph-queries resource group** check box if you
119
+
> want to provide the name of an existing resource group to save the shared query into. Using the
120
+
> default named resource group for queries makes Shared queries easier to discover. It also makes
121
+
> the purpose of that resource group more apparent. However, you might opt to select an existing
122
+
> resource group for security reasons based on existing permissions.
97
123
98
-
1. Move away from Azure Resource Graph Explorer in the Azure portal and then return to it. Notice that the saved query is no longer displayed and the **Query 1** tab has returned.
124
+
1. Move away from Azure Resource Graph Explorer in the Azure portal and then return to it. Notice
125
+
that the saved query is no longer displayed and the **Query 1** tab has returned.
99
126
100
-
1. Select **Open a query**. Verify that the type is set to **Shared query** and the combination of **Subscription** and **Resource group** match where you saved the query. The saved **Count VMs by OS** item now appears in the **Query Name** list. Select the title link of the saved query to load it into a new tab with that query's name. As a Shared query, it displays an icon in the tab next to the title, denoting it as shared.
127
+
1. Select **Open a query**. Verify that the type is set to **Shared query** and the combination of
128
+
**Subscription** and **Resource group** match where you saved the query. The saved **Count VMs by
129
+
OS** item now appears in the **Query Name** list. Select the title link of the saved query to
130
+
load it into a new tab with that query's name. As a Shared query, it displays an icon in the tab
131
+
next to the title, denoting it as shared.
101
132
102
133

103
134
104
-
> [!NOTE]
105
-
> When a saved query is open and the tab shows its name, the **Save** button updates it with any changes that have been made. To create a new saved query, select **Save as** and proceed as if you were saving a brand new query.
135
+
> [!NOTE] When a saved query is open and the tab shows its name, the **Save** button updates it
136
+
> with any changes that have been made. To create a new saved query, select **Save as** and
137
+
> proceed as if you were saving a brand new query.
106
138
107
139
## Discover Shared queries
108
140
@@ -115,20 +147,30 @@ Because a Shared query is a Resource Manager resource, there are several ways to
115
147
116
148
### View Resource Graph queries
117
149
118
-
In the Azure portal, the Resource Graph queries page displays Shared queries that the logged-in account has access to. This page enables filtering by name, subscription, resource group, and other properties of the Resource Graph query. You can also tag, export, and delete Resource Graph queries by using this interface.
150
+
In the Azure portal, the Resource Graph queries page displays Shared queries that the logged-in
151
+
account has access to. This page enables filtering by name, subscription, resource group, and other
152
+
properties of the Resource Graph query. You can also tag, export, and delete Resource Graph queries
153
+
by using this interface.
119
154
120
-
Selecting one of the queries opens the Resource Graph query page. Like other Resource Manager resources, this page offers an interactive overview along with the Activity log, access control, and tags. You can also apply a resource lock directly from this page.
155
+
Selecting one of the queries opens the Resource Graph query page. Like other Resource Manager
156
+
resources, this page offers an interactive overview along with the Activity log, access control, and
157
+
tags. You can also apply a resource lock directly from this page.
121
158
122
-
Get to the Resource Graph queries page from the portal menu by selecting **All services** or by using the Azure search box at the top of all pages. Search for and select **Resource Graph Explorer**.
159
+
Get to the Resource Graph queries page from the portal menu by selecting **All services** or by
160
+
using the Azure search box at the top of all pages. Search for and select **Resource Graph
161
+
Explorer**.
123
162
124
163
### List Resource groups resources
125
164
126
-
The Resource Graph query is listed alongside other resources that are part of a resource group. Selecting the Resource Graph query opens the page for that query. The ellipsis and shortcut menu options (triggered by right-clicking) work the same as on the Resource Graph query page.
165
+
The Resource Graph query is listed alongside other resources that are part of a resource group.
166
+
Selecting the Resource Graph query opens the page for that query. The ellipsis and shortcut menu
167
+
options (triggered by right-clicking) work the same as on the Resource Graph query page.
127
168
128
169
### Query Resource Graph
129
170
130
-
You can find Resource Graph queries through a query to Resource Graph. The following Resource Graph query limits by type `Microsoft.ResourceGraph/queries`, and then uses
131
-
`project` to list only the name, time modified, and the query itself:
171
+
You can find Resource Graph queries through a query to Resource Graph. The following Resource Graph
172
+
query limits by type `Microsoft.ResourceGraph/queries`, and then uses `project` to list only the
173
+
name, time modified, and the query itself:
132
174
133
175
```kusto
134
176
Resources
@@ -138,7 +180,10 @@ Resources
138
180
139
181
## Delete a Shared query
140
182
141
-
If a Shared query is no longer needed, delete it. By deleting a Shared query, you remove the corresponding Resource Manager resource. Any dashboards that the results chart was pinned to now display an error message. When that error message is displayed, use the **Remove from dashboard** button to clean up your dashboard.
183
+
If a Shared query is no longer needed, delete it. By deleting a Shared query, you remove the
184
+
corresponding Resource Manager resource. Any dashboards that the results chart was pinned to now
185
+
display an error message. When that error message is displayed, use the **Remove from dashboard**
186
+
button to clean up your dashboard.
142
187
143
188
You can delete a Shared query through the following interfaces:
144
189
- Resource Graph queries page
@@ -148,7 +193,8 @@ You can delete a Shared query through the following interfaces:
148
193
149
194
## Clean up resources
150
195
151
-
When you're finished with this tutorial, delete the Private and Shared queries you created if you no longer want them.
196
+
When you're finished with this tutorial, delete the Private and Shared queries you created if you no
0 commit comments