Skip to content

Commit 79f75e2

Browse files
committed
updates arg bicep quickstart
1 parent b56346e commit 79f75e2

File tree

2 files changed

+102
-57
lines changed

2 files changed

+102
-57
lines changed
Lines changed: 98 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,153 @@
11
---
2-
title: 'Quickstart: Create a shared query with Bicep'
3-
description: In this quickstart, you use Bicep to create a Resource Graph shared query that counts virtual machines by OS.
4-
author: rayoef
5-
ms.author: rayoflores
6-
ms.date: 05/17/2022
2+
title: "Quickstart: Create Resource Graph shared query using Bicep"
3+
description: In this quickstart, you use Bicep to create an Azure Resource Graph shared query that counts virtual machines by OS.
4+
ms.date: 06/26/2024
75
ms.topic: quickstart
86
ms.custom: subject-armqs, mode-arm, devx-track-bicep
97
---
10-
# Quickstart: Create a shared query using Bicep
118

12-
[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
1310

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

2113
[!INCLUDE [About Bicep](../../../includes/resource-manager-quickstart-bicep-introduction.md)]
2214

2315
## Prerequisites
2416

25-
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/).
2620

27-
## Review the Bicep file
21+
## Connect to Azure
2822

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

31-
The Bicep file used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/resourcegraph-sharedquery-countos/).
25+
# [Azure CLI](#tab/azure-cli)
3226

33-
:::code language="bicep" source="~/quickstart-templates/demos/resourcegraph-sharedquery-countos/main.bicep":::
27+
```azurecli
28+
az login
3429
35-
The resource defined in the Bicep file is:
30+
# Run these commands if you have multiple subscriptions
31+
az account list --output table
32+
az account set --subscription <subscriptionID>
33+
```
3634

37-
- [Microsoft.ResourceGraph/queries](/azure/templates/microsoft.resourcegraph/queries)
35+
# [Azure PowerShell](#tab/azure-powershell)
3836

39-
## Deploy the Bicep file
37+
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.
4038

41-
1. Save the Bicep file as **main.bicep** to your local computer.
39+
```azurepowershell
40+
Connect-AzAccount
4241
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+
```
4646

47-
1. Deploy the Bicep file using either Azure CLI or Azure PowerShell.
47+
---
4848

49-
# [CLI](#tab/CLI)
49+
## Review the Bicep file
5050

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).
5552

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.
58+
59+
:::code language="bicep" source="~/quickstart-templates/demos/resourcegraph-sharedquery-countos/main.bicep":::
5760

58-
```azurepowershell
59-
New-AzResourceGroup -Name exampleRG -Location eastus
60-
New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep
61-
```
61+
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).
6262

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

65-
When the deployment finishes, you should see a message indicating the deployment succeeded.
67+
# [Azure CLI](#tab/azure-cli)
6668

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+
```
6873

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).
74+
# [Azure PowerShell](#tab/azure-powershell)
75+
76+
```azurepowershell
77+
New-AzResourceGroup -Name exampleRG -Location eastus
78+
New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile main.bicep
79+
```
80+
81+
---
82+
83+
The deployment outputs messages to your shell. When the deployment is finished, your shell returns to a command prompt.
7184

7285
## Review deployed resources
7386

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

76-
# [CLI](#tab/CLI)
89+
# [Azure CLI](#tab/azure-cli)
7790

78-
```azurecli-interactive
91+
```azurecli
7992
az resource list --resource-group exampleRG
8093
```
8194

82-
# [PowerShell](#tab/PowerShell)
95+
# [Azure PowerShell](#tab/azure-powershell)
8396

84-
```azurepowershell-interactive
85-
Get-AzResource -ResourceGroupName exampleRG
97+
```azurepowershell
98+
Get-AzResource -ResourceGroupName exampleRG
8699
```
87100

88101
---
89102

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+
90123
## Clean up resources
91124

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

94-
# [CLI](#tab/CLI)
127+
# [Azure CLI](#tab/azure-cli)
95128

96-
```azurecli-interactive
129+
```azurecli
97130
az group delete --name exampleRG
98131
```
99132

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)
101140

102-
```azurepowershell-interactive
141+
```azurepowershell
103142
Remove-AzResourceGroup -Name exampleRG
104143
```
105144

145+
To sign out of your Azure PowerShell session:
146+
147+
```azurepowershell
148+
Disconnect-AzAccount
149+
```
150+
106151
---
107152

108153
## Next steps
@@ -112,4 +157,4 @@ In this quickstart, you created a Resource Graph shared query using Bicep.
112157
To learn more about shared queries, continue to the tutorial for:
113158

114159
> [!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)

articles/governance/resource-graph/shared-query-template.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: 'Quickstart: Create a shared query with ARM template'
2+
title: 'Quickstart: Create Resource Graph shared query using ARM template'
33
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.
4-
ms.date: 06/21/2024
4+
ms.date: 06/26/2024
55
ms.topic: quickstart
66
ms.custom: subject-armqs, mode-arm, devx-track-arm-template
77
---
88

9-
# Quickstart: Create a shared query by using an ARM template
9+
# Quickstart: Create Resource Graph shared query using ARM template
1010

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

1313
[!INCLUDE [About Azure Resource Manager](../../../includes/resource-manager-quickstart-introduction.md)]
1414

0 commit comments

Comments
 (0)