@@ -7,162 +7,173 @@ ms.date: 10/23/2019
7
7
ms.topic : tutorial
8
8
ms.service : resource-graph
9
9
---
10
- # Tutorial: Create and share an Azure Resource Graph query in Azure portal
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 right in Azure portal. There
13
- are two types of queries, _ Private_ and _ Shared_ . A _ Private _ query is saved in your Azure portal
14
- settings, but a _ Shared _ query is a Resource Manager resource that can be managed with role-based
15
- 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.
16
16
17
- Saving queries in Azure portal saves your time spent looking for your favorite or commonly used
18
- queries. When sharing queries, you enable your team to be consistent and repeatable. In this
19
- tutorial, you'll complete these steps:
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.
20
+
21
+ In this tutorial, you'll complete the following tasks:
20
22
21
23
> [ !div class="checklist"]
22
- > - Create and delete a _ Private _ query
23
- > - Create a _ Shared _ query
24
- > - Discover _ Shared _ queries
25
- > - Delete a _ Shared _ query
24
+ > - Create and delete a Private query
25
+ > - Create a Shared query
26
+ > - Discover Shared queries
27
+ > - Delete a Shared query
26
28
27
29
## Prerequisites
28
30
29
- To complete this tutorial, you need an Azure subscription. If you don't have an Azure subscription,
30
- 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.
31
33
32
34
## Create and delete a Private query
33
35
34
- _ Private _ queries are only accessible or visible to the account that creates them. As they're saved
35
- in an account's Azure portal settings, they can only be created, used, and deleted from inside Azure
36
- portal. A _ Private _ query isn't a Resource Manager resource. Create a new _ Private _ query by
37
- following 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:
38
40
39
- 1 . From the portal menu, select ' All services' or use the Azure search box at the top of all pages.
40
- Search for and 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** .
41
43
42
- 1 . In the 'Query 1' tab on the Azure Resource Graph Explorer page, enter the following query. For
43
- information about this query, see
44
- [ Samples - Count virtual machines by OS type] ( ../samples/starter.md#count-virtual-machines-by-os-type ) .
45
- Select ** Run query** to see the query results in th lower pane.
44
+ 1 . On the ** Query 1** tab on the Azure Resource Graph Explorer page, enter the following query:
46
45
47
46
``` kusto
48
47
Resources
49
48
| where type =~ 'Microsoft.Compute/virtualMachines'
50
49
| summarize count() by tostring(properties.storageProfile.osDisk.osType)
51
50
```
52
51
53
- 1 . Select ** Save** or ** Save as** , enter the _ Name_ as 'Count VMs by OS', leave _ Type_ as 'Private
54
- query', then select ** Save** at the bottom of the _ Save query_ pane. The title of the tab changes
55
- from 'Query 1' to 'Count VMs by OS'.
52
+ Select ** Run query** to see the query results in the bottom pane.
53
+
54
+ For more information about this query, see
55
+ [ Samples – Count virtual machines by OS type] ( ../samples/starter.md#count-virtual-machines-by-os-type ) .
56
+
56
57
57
- 1 . Browse away from Azure Resource Graph Explorer in Azure portal and then return to it. The saved
58
- query is no longer displayed and the 'Query 1' tab has returned.
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** .
59
61
60
- 1 . Select ** Open a query** . Check that _ Type_ is 'Private query'. The saved 'Count VMs by OS' now
61
- appears in the _ Query Name_ list. Select the title link of the saved query and it's loaded into a
62
- new tab with that queries name.
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.
63
64
64
- > [ !NOTE]
65
- > When a saved query is open and the tab shows it's _ Name_ , the ** Save** button updates it with
66
- > any changes made. To create a new saved query, use ** Save as** and follow the steps as if it
67
- > was a brand new saved query.
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.
68
68
69
- 1 . To delete the saved query, select ** Open a query** again, and check that _ Type_ is 'Private
70
- query'. On the row of the saved 'Count VMs by OS' query, select the trash can icon. On the
71
- confirmation dialog, select ** Yes** to complete the deletion of the query. Then close the _ Open a
72
- query_ pane.
69
+ > [ !NOTE]
70
+ > When a saved query is open and the tab shows its name, selecting the ** Save** button
71
+ > updates it with any changes that have been made. To create a new saved query from this open
72
+ > query, select ** Save as** and proceed as if you were saving a brand new query.
73
+
74
+ 1 . To delete the saved query, select ** Open a query** again, and verify that the ** Type** field is
75
+ set to ** Private query** . On the row of the saved ` Count VMs by OS ` query, select ** Delete**
76
+ (Recycle bin icon). In the confirmation dialog box, select ** Yes** to finish deleting the query.
77
+ Then, close the ** Open a query** pane.
73
78
74
79
## Create a Shared query
75
80
76
- Unlike a _ Private _ query, a _ Shared _ query is a Resource Manager resource. This fact means the query
77
- gets saved to a resource group, can be managed and controlled with RBAC, and even protected with
78
- resource locks. As a resource, anyone with appropriate permissions can see and use it. Create a new
79
- _ Shared _ query by following these steps:
81
+ Unlike a Private query, a Shared query is a Resource Manager resource. This fact means the query
82
+ gets saved to a resource group, can be managed and controlled with RBAC, and can even be protected
83
+ with resource locks. As a resource, anyone who has the appropriate permissions can see and use it.
84
+ To create a new Shared query, follow these steps:
80
85
81
- 1 . From the portal menu, select ' All services' or use the Azure search box at the top of all pages.
82
- Search for and select ' Resource Graph Explorer' .
86
+ 1 . From the portal menu, select ** All services** , or use the Azure search box at the top of all
87
+ pages to search for and select ** Resource Graph Explorer** .
83
88
84
- 1 . In the 'Query 1' tab on the Azure Resource Graph Explorer page, enter the following query. For
85
- information about this query, see
86
- [ Samples - Count virtual machines by OS type] ( ../samples/starter.md#count-virtual-machines-by-os-type ) .
87
- Select ** Run query** to see the query results in the lower pane.
89
+ 1 . On the ** Query 1** tab on the Azure Resource Graph Explorer page, enter the following query:
88
90
89
91
``` kusto
90
92
Resources
91
93
| where type =~ 'Microsoft.Compute/virtualMachines'
92
94
| summarize count() by tostring(properties.storageProfile.osDisk.osType)
93
95
```
96
+
97
+ Select ** Run query** to see the query results in the bottom pane.
98
+
99
+ For more information about this query, see
100
+ [ Samples – Count virtual machines by OS type] ( ../samples/starter.md#count-virtual-machines-by-os-type ) .
94
101
95
102
1 . Select ** Save** or ** Save as** .
96
103
104
+
97
105
![ Save the new query using the save button] ( ../media/create-share-query/save-shared-query-buttons.png )
98
106
99
- 1 . In the _ Save query_ pane, enter the _ Name_ as 'Count VMs by OS', change _ Type_ to 'Shared query',
100
- set _ Description_ to 'Count of virtual machines by OS type', and select the _ Subscription_ where
101
- the query resource gets created. Leave the 'Publish to resource-graph-queries resource group'
102
- checkbox checked and the _ Resource Group location_ set to '(US) West Central US'. Then select
103
- ** Save** at the bottom of the _ Save query_ pane. The title of the tab changes from 'Query 1' to
104
- 'Count VMs by OS'. The first time 'resource-graph-queries' resource group is used, the save takes
105
- longer as the resource group is created.
106
-
107
- ![ Save the new query as a Shared Query] ( ../media/create-share-query/save-shared-query-window.png )
108
-
109
- > [ !NOTE]
110
- > If desired, remove the check to provide the name of an existing resource group to save the
111
- > shared query into. Using the default named resource group for queries makes _ Shared_ queries
112
- > easier to discover. It also makes more apparent the purpose of that resource group. However,
113
- > selecting an existing resource group may be done for security reasons based on existing
114
- > permissions.
115
-
116
- 1 . Browse away from Azure Resource Graph Explorer in Azure portal and then return to it. The saved
117
- query is no longer displayed and the 'Query 1' tab has returned.
118
-
119
- 1 . Select ** Open a query** . Check that _ Type_ is 'Shared query' and the combination of
120
- _ Subscription_ and _ Resource group_ match where you saved the query. The saved 'Count VMs by OS'
121
- now appears in the _ Query Name_ list. Select the title link of the saved query and it's loaded
122
- into a new tab with that queries name. As a _ Shared_ query, it displays an icon in the tab next
123
- to the title denoting it as shared.
107
+ 1 . In the ** Save query** pane, enter ** Count VMs by OS** for the name.
108
+ 1 . Change the type to ** Shared query** , set the description to ** Count of virtual machines by OS
109
+ type** , and set ** Subscription** to specify where the query resource gets created.
110
+ 1 . Leave the ** Publish to resource-graph-queries resource group** check box selected and the
111
+ ** Resource Group location** set to ** (US) West Central US** .
112
+ 1 . Select ** Save** at the bottom of the ** Save query** pane. The tab title changes from ** Query 1**
113
+ to ** Count VMs by OS** . The first time the ** resource-graph-queries** resource group is used, the
114
+ save takes longer than expected as the resource group gets created.
115
+
116
+
117
+ ![ Save the new query as a Shared query] ( ../media/create-share-query/save-shared-query-window.png )
118
+
119
+ > [ !NOTE]
120
+ > You can clear the ** Publish to resource-graph-queries resource group** check box if you
121
+ > want to provide the name of an existing resource group to save the shared query into. Using the
122
+ > default named resource group for queries makes Shared queries easier to discover. It also makes
123
+ > the purpose of that resource group more apparent. However, you might opt to select an existing
124
+ > resource group for security reasons based on existing permissions.
125
+
126
+ 1 . Move away from Azure Resource Graph Explorer in the Azure portal and then return to it. Notice
127
+ that the saved query is no longer displayed and the ** Query 1** tab has returned.
128
+
129
+ 1 . Select ** Open a query** . Verify that the type is set to ** Shared query** and the combination of
130
+ ** Subscription** and ** Resource group** match where you saved the query. The saved ** Count VMs by
131
+ OS** item now appears in the ** Query Name** list. Select the title link of the saved query to
132
+ load it into a new tab with that query's name. As a Shared query, it displays an icon in the tab
133
+ next to the title, denoting it as shared.
124
134
125
135
![ Show the Shared Query with icon] ( ../media/create-share-query/show-saved-shared-query.png )
126
136
127
- > [ !NOTE]
128
- > When a saved query is open and the tab shows it's _ Name _ , the ** Save** button updates it with
129
- > any changes made. To create a new saved query, use ** Save as** and follow the steps as if it
130
- > was a brand new saved query.
137
+ > [ !NOTE]
138
+ > When a saved query is open and the tab shows its name , the ** Save** button updates it
139
+ > with any changes that have been made. To create a new saved query, select ** Save as** and
140
+ > proceed as if you were saving a brand new query.
131
141
132
142
## Discover Shared queries
133
143
134
- As a _ Shared _ query is a Resource Manager resource, there are several ways to find them :
144
+ Because a Shared query is a Resource Manager resource, there are several ways to find one :
135
145
136
- - From Resource Graph Explorer, select ** Open a query** and set _ Type _ to ' Shared query'
137
- - The Resource Graph queries portal page
138
- - The resource group it was saved in
139
- - With a query to Resource Graph
146
+ - From Resource Graph Explorer, select ** Open a query** and set the type to ** Shared query** .
147
+ - From the Resource Graph queries portal page.
148
+ - From the resource group that the Shared query was saved in.
149
+ - Through a query to Resource Graph.
140
150
141
151
### View Resource Graph queries
142
152
143
- In Azure portal, the Resource Graph queries page displays _ Shared _ queries that the logged in
144
- account has access to. This page allows filtering by name, subscription, resource group, and other
145
- properties of the Resource Graph query. Resource Graph queries can also be tagged, exported , and
146
- deleted using this interface.
153
+ In the Azure portal, the Resource Graph queries page displays Shared queries that the logged- in
154
+ account has access to. This page enables filtering by name, subscription, resource group, and other
155
+ properties of the Resource Graph query. You can also tag, export , and delete Resource Graph queries
156
+ by using this interface.
147
157
148
158
Selecting one of the queries opens the Resource Graph query page. Like other Resource Manager
149
159
resources, this page offers an interactive overview along with the Activity log, access control, and
150
- tags. A resource lock can also be applied directly from this page.
160
+ tags. You can also apply a resource lock directly from this page.
151
161
152
- Get to the Resource Graph queries page from the portal menu by selecting 'All services' or using the
153
- Azure search box at the top of all pages. Search for and select 'Resource Graph Explorer'.
162
+ Get to the Resource Graph queries page from the portal menu by selecting ** All services** or by
163
+ using the Azure search box at the top of all pages. Search for and select ** Resource Graph
164
+ Explorer** .
154
165
155
166
### List Resource groups resources
156
167
157
168
The Resource Graph query is listed alongside other resources that are part of a resource group.
158
- Selecting the Resource Graph query opens the page for that query. The ellipsis or right-click
159
- options work the same as the Resource Graph query page.
169
+ Selecting the Resource Graph query opens the page for that query. The ellipsis and shortcut menu
170
+ options (triggered by right-clicking) work the same as on the Resource Graph query page.
160
171
161
172
### Query Resource Graph
162
173
163
- As a Resource Manager resource, Resource Graph queries can be found with a query to Resource Graph.
164
- The following Resource Graph query limits by type ` Microsoft.ResourceGraph/queries ` , and then uses
165
- ` project ` to list only the name, time modified, and the query itself:
174
+ You can find Resource Graph queries through a query to Resource Graph. The following Resource Graph
175
+ query limits by type ` Microsoft.ResourceGraph/queries ` , and then uses ` project ` to list only the
176
+ name, time modified, and the query itself:
166
177
167
178
``` kusto
168
179
Resources
@@ -172,27 +183,27 @@ Resources
172
183
173
184
## Delete a Shared query
174
185
175
- If a _ Shared _ query is no longer needed, delete it. Deleting a _ Shared _ query removes the actual
176
- Resource Manager resource. Any dashboards the results chart was pinned to now display an error
177
- message. When that error message is displayed, use the ** Remove from dashboard** button to clean up
178
- your dashboard.
186
+ If a Shared query is no longer needed, delete it. By deleting a Shared query, you remove the
187
+ corresponding Resource Manager resource. Any dashboards that the results chart was pinned to now
188
+ display an error message. When that error message is displayed, use the ** Remove from dashboard**
189
+ button to clean up your dashboard.
179
190
180
- A _ Shared _ query can be deleted from the following interfaces:
191
+ You can delete a Shared query through the following interfaces:
181
192
- Resource Graph queries page
182
193
- Resource Graph query page
183
- - Resource Graph Explorer's Open a query page
194
+ - The ** Open a query** page in Resource Graph Explorer
184
195
- Resource groups page
185
196
186
197
## Clean up resources
187
198
188
- When you're finished with this tutorial, delete the _ Private _ and _ Shared _ queries you created if
189
- you no longer want them.
199
+ When you're finished with this tutorial, delete the Private and Shared queries you created if you no
200
+ longer want them.
190
201
191
202
## Next steps
192
203
193
- - Run your first query with [ Azure portal] ( ../first-query-portal.md )
194
- - Get more information about the [ query language] ( ../concepts/query-language.md )
195
- - Learn to [ explore resources] ( ../concepts/explore-resources.md )
196
- - See samples of [ Starter queries] ( ../samples/starter.md )
197
- - See samples of [ Advanced queries] ( ../samples/advanced.md )
198
- - Provide feedback on [ UserVoice] ( https://feedback.azure.com/forums/915958-azure-governance )
204
+ - Run your first query by using the [ Azure portal] ( ../first-query-portal.md ) .
205
+ - Get more information about the [ query language] ( ../concepts/query-language.md ) .
206
+ - Learn more about how to [ explore resources] ( ../concepts/explore-resources.md ) .
207
+ - See samples of [ Starter queries] ( ../samples/starter.md ) .
208
+ - See samples of [ Advanced queries] ( ../samples/advanced.md ) .
209
+ - Provide feedback on [ UserVoice] ( https://feedback.azure.com/forums/915958-azure-governance ) .
0 commit comments