Using azure managementresource with cognitive
TypeScriptWith Pulumi, you can automate the provisioning of cloud resources, and in this case, you're interested in creating resources related to Azure Cognitive Services using the Azure Resource Manager (ARM). Azure Cognitive Services offer a range of AI services that provide capabilities like vision, speech, language, and decision support through APIs.
Let’s create an Azure Cognitive Services account using Pulumi with TypeScript. This account is a prerequisite for accessing various cognitive services on Azure. To accomplish this, we'll be using the
azure-native.cognitiveservices.Account
resource which allows you to create and manage a Cognitive Services account on Azure.Below is a program written in TypeScript that deploys a new Cognitive Services account:
import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; const resourceGroup = new azure_native.resources.ResourceGroup("my-resource-group"); const cognitiveServicesAccount = new azure_native.cognitiveservices.Account("myCognitiveAccount", { resourceGroupName: resourceGroup.name, kind: "CognitiveServices", // Specifies the kind of cognitive service to create sku: { name: "S0", // Represents the pricing tier for the cognitive service }, location: resourceGroup.location, // You would replace this with your desired region }); // Export the endpoint of the created Cognitive Services account export const endpoint = cognitiveServicesAccount.endpoint;
In this program:
- We start by importing the required Pulumi packages.
- A new resource group is created using
azure_native.resources.ResourceGroup
. Resource groups in Azure are containers that hold related resources for an Azure solution. - Using
azure_native.cognitiveservices.Account
, we create a Cognitive Services Account within the specified resource group.kind
specifies that we want to create a Cognitive Services account.sku
represents the pricing tier of the account, which here we've selected "S0".- The location for the Cognitive Services account is set to the same location as our resource group. Make sure to replace this with the Azure region you prefer.
- Lastly, we export the endpoint so that you can access your Cognitive Services account after it’s been deployed.
The
kind
specifies the type of cognitive service you want to provision. Thesku
reflects the service's pricing tier, which in this example is "S0", a standard pricing tier. Adjust these values according to your requirements and the specific cognitive service you wish to use.To deploy this program:
- Install Pulumi and set up the Azure CLI with an account that has sufficient permissions.
- Run
pulumi new typescript
in your terminal and select the Azure template to create a new Pulumi TypeScript project. - Replace the contents of
index.ts
with the code shown above. - Run
pulumi up
to preview and deploy the resources. Follow the prompts by the CLI to complete the deployment.
After deployment, Pulumi provides you with the outputs defined in the program, which in this case includes the endpoint URL of the Cognitive Services account. You can use this endpoint to configure your application to use the cognitive services.