Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Det finns många sätt att skapa nya resurser på Azure. Bicep-filer ger en deklarativ, modulär och återanvändbar metod för att definiera Azure-resurser. Bicep-mallar ger förbättrad läsbarhet, underhåll och intern integrering med Azure Resource Manager (ARM) jämfört med JSON-baserade ARM-mallar eller imperativa skriptmetoder som PowerShell och Azure CLI. GitHub Copilot för Azure kan hjälpa dig att skapa Bicep-filer.
Generera Bicep-filer
Att komma igång med Bicep-filer kan kräva viss utbildning om du inte har använt syntaxen tidigare, men verktyg som GitHub Copilot för Azure kan vara till hjälp.
Exempelscenario
Anta att du vill ha ett enkelt sätt att skapa en repeterbar och automatiserad process för att skapa en blobcontainer och en fildelning. Du kanske är bekant med hur du skapar en blobcontainer och en fildelning med hjälp av Azure-portalen, men är osäker på hur du använder Bicep-filer för att göra samma sak.
Exempelprompt
Skapa en ny chatt (Ctrl + L) och kopiera och klistra sedan in följande uppmaning i GitHub Copilots chattfönster.
Show me a Bicep file that creates an Azure Storage account with a blob container and a file share.
Exempelsvar
Anmärkning
Följande svar är ett exempel. GitHub Copilot för Azure-svar är icke-terministiska, så du kan få ett annat svar än det som visas här.
GitHub Copilot för Azure genererar en Bicep-fil som liknar följande.
@description('Specifies the name of the Azure Storage account.')
param storageAccountName string
@description('Specifies the name of the blob container to create.')
param blobContainerName string
@description('Specifies the name of the file share to create.')
param fileShareName string
@description('Specifies the location in which the Azure Storage resources should be deployed.')
param location string = resourceGroup().location
resource sa 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}
resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2023-01-01' = {
parent: sa
name: 'default'
}
resource blobContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2023-01-01' = {
parent: blobServices
name: blobContainerName
properties: {
publicAccess: 'None'
}
}
resource fileServices 'Microsoft.Storage/storageAccounts/fileServices@2023-01-01' = {
parent: sa
name: 'default'
}
resource fileShare 'Microsoft.Storage/storageAccounts/fileServices/shares@2023-01-01' = {
parent: fileServices
name: fileShareName
properties: {
shareQuota: 100 // Quota in MB
}
}
Skapa en ny main.bicep-fil och kopiera sedan svaret från GitHub Copilot för Azure och klistra in i den nya filen.
När du använder Azure CLI för att köra Bicep-filen kan du ange paramerna deklarerade som storageAccountName, blobContainerNameoch fileShareName.
Du kan också redigera Bicep-filen genom att initiera storageAccountName parametern till ditt önskade värde.
param storageAccountName string = '<your-storage-account-name>'
Förfina svaret
Men om du är nybörjare på Bicep-filer kan du behöva mer information. Fortsätt att fråga i samma chattsession för att förstå nästa steg.
Du kan till exempel fråga var den här Bicep-filen ska skapas på VS Code-arbetsytan.
Where in my workspace should I create the Azure Bicep file, and what should I call it?
Den kan svara genom att föreslå en mapp och ett filnamn för din nya Bicep-fil. Till exempel infra/storageAccount.bicep.
Om du är osäker på hur du distribuerar Bicep-filen kan du skapa en uppmaning som ber om instruktioner.
How do I execute the Azure Bicep file?
Du kan få ett svar som liknar följande.
To execute the Bicep file, you can use the Azure CLI with the following steps:
1. **Install Azure CLI and Bicep CLI**: Ensure you have the Azure CLI and Bicep CLI installed. You can install Bicep using the Azure CLI with the command:
az bicep install
2. **Log in to Azure**: Use the Azure CLI to log in to your Azure account:
az login
3. **Deploy the Bicep file**: Use the `az deployment group create` command to deploy the Bicep file to a resource group. Replace `<resource-group-name>` with your resource group name and `<location>` with your desired Azure region:
az deployment group create --resource-group <resource-group-name> --template-file infra/storageAccount.bicep --parameters storageAccountName=<your-storage-account-name> containerName=<your-container-name> fileShareName=<your-file-share-name> location=<location>
This command will deploy the resources defined in your Bicep file to the specified resource group in Azure.
Om du fastnar eller stöter på ett problem kan du fortsätta att ställa följdfrågor till GitHub Copilot för att skapa uppmaningar som inkluderar ordet azure i chattfönstret.