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
[Azure Resource Graph](../../governance/resource-graph/overview.md) is an Azure service designed to extend Azure Resource Management by providing efficient and performant resource exploration with the ability to query at scale across a given set of subscriptions so you can effectively govern your environment. With Resource Graph queries, you can:
9
+
# Quickstart: Create Resource Graph shared query using Bicep
13
10
14
-
- Query resources with complex filtering, grouping, and sorting by resource properties.
15
-
- Explore resources iteratively based on governance requirements.
16
-
- Assess the impact of applying policies in a vast cloud environment.
17
-
-[Query changes made to resource properties](./how-to/get-resource-changes.md) (preview).
18
-
19
-
Resource Graph queries can be saved as a _private query_ or a _shared query_. A private query is saved to the individual's Azure portal profile and isn't visible to others. A shared query is a Resource Manager object that can be shared with others through permissions and role-based access. A shared query provides common and consistent execution of resource discovery. This quickstart uses Bicep to create a shared query.
11
+
In this quickstart, you use Bicep to create an Azure Resource Graph shared query. Resource Graph queries can be saved as a _private query_ or a _shared query_. A private query is saved to the individual's Azure portal profile and isn't visible to others. A shared query is a Resource Manager object that can be shared with others through permissions and role-based access. A shared query provides common and consistent execution of resource discovery.
If you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account before you begin.
17
+
- If you don't have an Azure account, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
18
+
-[Azure CLI](/cli/azure/install-azure-cli) or [PowerShell](/powershell/scripting/install/installing-powershell) and [Azure PowerShell](/powershell/azure/install-azure-powershell).
19
+
-[Visual Studio Code](https://code.visualstudio.com/).
26
20
27
-
## Review the Bicep file
21
+
## Connect to Azure
28
22
29
-
In this quickstart, you create a shared query called _Count VMs by OS_. To try this query in SDK or in portal with Resource Graph Explorer, see [Samples - Count virtual machines by OS type](./samples/starter.md#count-virtual-machines-by-os-type).
23
+
From a Visual Studio Code terminal session, connect to Azure. If you have more than one subscription, run the commands to set context to your subscription. Replace `<subscriptionID>` with your Azure subscription ID.
30
24
31
-
The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/resourcegraph-sharedquery-countos/).
From a Visual Studio Code terminal session, connect to Azure. If you have more than one subscription, run the commands to set context to your subscription. Replace `<subscriptionID>` with your Azure subscription ID.
40
38
41
-
1. Save the Bicep file as **main.bicep** to your local computer.
39
+
```azurepowershell
40
+
Connect-AzAccount
42
41
43
-
> [!NOTE]
44
-
> The Bicep file isn't required to be named **main.bicep**. If you save the file with a different name, you must change the name of
45
-
> the template file in the deployment step below.
42
+
# Run these commands if you have multiple subscriptions
43
+
Get-AzSubScription
44
+
Set-AzContext -Subscription <subscriptionID>
45
+
```
46
46
47
-
1. Deploy the Bicep file using either Azure CLI or Azure PowerShell.
47
+
---
48
48
49
-
# [CLI](#tab/CLI)
49
+
## Review the Bicep file
50
50
51
-
```azurecli
52
-
az group create --name exampleRG --location eastus
53
-
az deployment group create --resource-group exampleRG --template-file main.bicep
54
-
```
51
+
In this quickstart, you create a shared query called _Count VMs by OS_. To try this query in SDK or in portal with Resource Graph Explorer, see [Samples - Count virtual machines by OS type](/previous-versions/azure/governance/resource-graph/samples/starter#count-virtual-machines-by-os-type).
55
52
56
-
# [PowerShell](#tab/PowerShell)
53
+
The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/resourcegraph-sharedquery-countos/).
54
+
55
+
1. Open Visual Studio Code and create a new file.
56
+
1. Copy and paste the Bicep file into your new file.
57
+
1. Save the file as _main.bicep_ on your local computer.
The resource defined in the Bicep file is: [Microsoft.ResourceGraph/queries](/azure/templates/microsoft.resourcegraph/queries). To learn how to create Bicep files, go to [Quickstart: Create Bicep files with Visual Studio Code](../../azure-resource-manager/bicep/quickstart-create-bicep-use-visual-studio-code.md).
62
62
63
-
---
63
+
## Deploy the Bicep file
64
+
65
+
Create a resource group and deploy the Bicep file with Azure CLI or Azure PowerShell. Make sure you're in the directory where you saved the Bicep file. Otherwise, you need to specify the path to the file.
64
66
65
-
When the deployment finishes, you should see a message indicating the deployment succeeded.
67
+
# [Azure CLI](#tab/azure-cli)
66
68
67
-
Some other resources:
69
+
```azurecli
70
+
az group create --name exampleRG --location eastus
71
+
az deployment group create --resource-group exampleRG --template-file main.bicep
72
+
```
68
73
69
-
- To see the template reference, go to [Azure template reference](/azure/templates/microsoft.resourcegraph/allversions).
70
-
- To learn how to create Bicep files, see [Quickstart: Create Bicep files with Visual Studio Code](../../azure-resource-manager/bicep/quickstart-create-bicep-use-visual-studio-code.md).
The deployment outputs messages to your shell. When the deployment is finished, your shell returns to a command prompt.
71
84
72
85
## Review deployed resources
73
86
74
-
Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group.
87
+
Use Azure CLI or Azure PowerShell to list the deployed resources in the resource group.
75
88
76
-
# [CLI](#tab/CLI)
89
+
# [Azure CLI](#tab/azure-cli)
77
90
78
-
```azurecli-interactive
91
+
```azurecli
79
92
az resource list --resource-group exampleRG
80
93
```
81
94
82
-
# [PowerShell](#tab/PowerShell)
95
+
# [Azure PowerShell](#tab/azure-powershell)
83
96
84
-
```azurepowershell-interactive
85
-
Get-AzResource -ResourceGroupName exampleRG
97
+
```azurepowershell
98
+
Get-AzResource -ResourceGroupName exampleRG
86
99
```
87
100
88
101
---
89
102
103
+
The output shows the shared query's name, resource group name, and resource ID.
104
+
105
+
## Run the shared query
106
+
107
+
You can verify the shared query works using Azure Resource Graph Explorer. To change the scope, use the **Scope** menu on the left side of the page.
108
+
109
+
1. Sign in to [Azure portal](https://portal.azure.com).
110
+
1. Enter _resource graph_ into the search field at the top of the page.
111
+
1. Select **Resource Graph Explorer**.
112
+
1. Select **Open query**.
113
+
1. Change **Type** to _Shared queries_.
114
+
1. Select the query _Count VMs by OS_.
115
+
1. Select **Run query** and the view output in the **Results** tab.
116
+
117
+
You can also run the query from your resource group.
118
+
119
+
1. In Azure, go to the resource group, _exampleRG_.
120
+
1. From the **Overview** tab, select the query _Count VMs by OS_.
121
+
1. Select the **Results** tab.
122
+
90
123
## Clean up resources
91
124
92
-
When you no longer need the resource that you created, delete the resource group using Azure CLI or Azure PowerShell.
125
+
When you no longer need the resource that you created, delete the resource group using Azure CLI or Azure PowerShell. And if you signed into Azure portal to run the query, be sure to sign out.
93
126
94
-
# [CLI](#tab/CLI)
127
+
# [Azure CLI](#tab/azure-cli)
95
128
96
-
```azurecli-interactive
129
+
```azurecli
97
130
az group delete --name exampleRG
98
131
```
99
132
100
-
# [PowerShell](#tab/PowerShell)
133
+
To sign out of your Azure CLI session:
134
+
135
+
```azurecli
136
+
az logout
137
+
```
138
+
139
+
# [Azure PowerShell](#tab/azure-powershell)
101
140
102
-
```azurepowershell-interactive
141
+
```azurepowershell
103
142
Remove-AzResourceGroup -Name exampleRG
104
143
```
105
144
145
+
To sign out of your Azure PowerShell session:
146
+
147
+
```azurepowershell
148
+
Disconnect-AzAccount
149
+
```
150
+
106
151
---
107
152
108
153
## Next steps
@@ -112,4 +157,4 @@ In this quickstart, you created a Resource Graph shared query using Bicep.
112
157
To learn more about shared queries, continue to the tutorial for:
113
158
114
159
> [!div class="nextstepaction"]
115
-
> [Manage queries in Azure portal](./tutorials/create-share-query.md)
160
+
> [Tutorial: Create and share an Azure Resource Graph query in the Azure portal](./tutorials/create-share-query.md)
Copy file name to clipboardExpand all lines: articles/governance/resource-graph/shared-query-template.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
---
2
-
title: 'Quickstart: Create a shared query with ARM template'
2
+
title: 'Quickstart: Create Resource Graph shared query using ARM template'
3
3
description: In this quickstart, you use an Azure Resource Manager template (ARM template) to create a Resource Graph shared query that counts virtual machines by OS.
# Quickstart: Create a shared query by using an ARM template
9
+
# Quickstart: Create Resource Graph shared query using ARM template
10
10
11
-
Resource Graph queries can be saved as a _private query_ or a _shared query_. A private query is saved to the individuals portal profile and isn't visible to others. A shared query is a Resource Manager object that can be shared with others through permissions and role-based access. A shared query provides common and consistent execution of resource discovery. This quickstart uses an Azure Resource Manager template (ARM template) to create a shared query.
11
+
In this quickstart, you use an Azure Resource Manager template (ARM template) to create a Resource Graph shared query. Resource Graph queries can be saved as a _private query_ or a _shared query_. A private query is saved to the individuals portal profile and isn't visible to others. A shared query is a Resource Manager object that can be shared with others through permissions and role-based access. A shared query provides common and consistent execution of resource discovery.
0 commit comments