Skip to content

Commit ff0b5dc

Browse files
authored
Merge pull request #94521 from v-rihow/create-share-query
edit pass: create-share-query
2 parents b889ff4 + 39c1a45 commit ff0b5dc

File tree

1 file changed

+121
-110
lines changed

1 file changed

+121
-110
lines changed

articles/governance/resource-graph/tutorials/create-share-query.md

Lines changed: 121 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,162 +7,173 @@ ms.date: 10/23/2019
77
ms.topic: tutorial
88
ms.service: resource-graph
99
---
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
1111

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.
1616

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:
2022

2123
> [!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
2628
2729
## Prerequisites
2830

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.
3133

3234
## Create and delete a Private query
3335

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:
3840

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**.
4143

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:
4645

4746
```kusto
4847
Resources
4948
| where type =~ 'Microsoft.Compute/virtualMachines'
5049
| summarize count() by tostring(properties.storageProfile.osDisk.osType)
5150
```
5251

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+
5657

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**.
5961

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.
6364

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.
6868

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.
7378

7479
## Create a Shared query
7580

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:
8085

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**.
8388

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:
8890

8991
```kusto
9092
Resources
9193
| where type =~ 'Microsoft.Compute/virtualMachines'
9294
| summarize count() by tostring(properties.storageProfile.osDisk.osType)
9395
```
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).
94101

95102
1. Select **Save** or **Save as**.
96103

104+
97105
![Save the new query using the save button](../media/create-share-query/save-shared-query-buttons.png)
98106

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.
124134

125135
![Show the Shared Query with icon](../media/create-share-query/show-saved-shared-query.png)
126136

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.
131141
132142
## Discover Shared queries
133143

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:
135145

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.
140150

141151
### View Resource Graph queries
142152

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.
147157

148158
Selecting one of the queries opens the Resource Graph query page. Like other Resource Manager
149159
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.
151161

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**.
154165

155166
### List Resource groups resources
156167

157168
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.
160171

161172
### Query Resource Graph
162173

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:
166177

167178
```kusto
168179
Resources
@@ -172,27 +183,27 @@ Resources
172183

173184
## Delete a Shared query
174185

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.
179190

180-
A _Shared_ query can be deleted from the following interfaces:
191+
You can delete a Shared query through the following interfaces:
181192
- Resource Graph queries page
182193
- Resource Graph query page
183-
- Resource Graph Explorer's Open a query page
194+
- The **Open a query** page in Resource Graph Explorer
184195
- Resource groups page
185196

186197
## Clean up resources
187198

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.
190201

191202
## Next steps
192203

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

Comments
 (0)