Managing "Grounding with Bing" resources through the Azure portal works fine for one-off deployments—but what happens when you need to deploy across multiple environments, integrate with CI/CD pipelines, or maintain consistent configurations at scale?
This blog shows you how to programmatically manage "Grounding with Bing" resources using Azure Resource Manager (ARM), giving you version-controlled, repeatable deployments that fit into your existing DevOps workflows.
In this blog, we are introducing Azure Resource Manager (ARM) to manage "Grounding with Bing" resources using programmatic deployments.
All code examples are available in our Github repository. Clone it to follow along or adapt for your own deployments.
Introduction
Azure Resource Manager (ARM) offers a unified platform for deploying, managing, and monitoring Azure resources, including custom search configurations. Utilizing ARM templates enables you to automate the provisioning and configuration of custom search resources, promoting consistency and repeatability across various environments. This method allows you to define search settings as code, integrate with CI/CD pipelines, and manage changes efficiently through version control. The ARM method can serve two purposes:
- Creating “Grounding with Bing Search” and “Grounding with Bing Custom Search” resources
- Creating, updating, and managing custom search configurations effectively and securely.
In this blog, we particularly give examples on “Grounding with Bing Custom Search”. There are approaches introduced to follow the ARM method: 1>REST API; 2> Python or C# SDK.
Approach 1 – Use REST API
Step 1 – login
> az login --tenant “yourTenantID"
> az login --scope https://management.core.windows.net//.default
> az account set --subscription “subscriptionID”
> az provider register –namespace
Step 2 – Register Bing search as an Azure resource provider
> az provider register --namespace 'Microsoft.Bing'
Step 3 – Prepare ARM template
arm-template.json
my-custom2-config.json
Step 4 – Get access token
> az account get-access-token –resource https://management.azure.com/
You will get result as follows:
Step 5 – Create Bing resource
This step will create “Bing-custom2” resource in “my-resourcegroup”.
Two methods are introduced.
- Method 1 – Using CLI
- Method 2 – Using CURL REST API
Below is example of create-bing-resource.REST
The Bing resource Bing-custom2 is created in Azure portal.
Step 6 – Create Bing configuration
In this step, you can configure Bing inclusion and exclusion list. Below is an example of create-update-config.REST.
Bing configuration Bing-custom2-config is created in Azure portal, with the configured allowed and blocked list.
Optional Step 7 – List Bing resource configuration
Below is example of list-config.REST
Optional Step 8 – Delete Bing configuration
Below is an example of delete-config.REST
Approach 2 – Use SDK
One step further, you can convert the above CURL commands of the REST APIs into Python or C# SDK.
For example, for the below CLI commands:
> az login --tenant “yourTenantID"
> az login --scope https://management.core.windows.net//.default
> az account set --subscription “subscriptionID”
> az account get-access-token –resource https://management.azure.com/
There are equivalent Python SDK, please reference Microsoft Learn article:
Deploy resources with Python and template - Azure Resource Manager | Microsoft Learn
Then you can add logic of creating Bing resource, configuring Bing inclusion, exclusion/blocked list in the Python or C# SDK. The full code is available in the github repository:
References:
Deploy resources with REST API and template - Azure Resource Manager | Microsoft Learn
Deploy resources with Python and template - Azure Resource Manager | Microsoft Learn
Acknowledgements:
Thanks Marta Lobo de Pablos, Matt Gotteiner and Linda (Zhuoqun) Li for providing guidance on the ARM approach and co-authoring the blog.