Bicep-fájlok létrehozása a GitHub Copilot for Azure használatával

Számos módon hozhat létre új erőforrásokat az Azure-ban. A Bicep-fájlok deklaratív, moduláris és újrafelhasználható megközelítést biztosítanak az Azure-erőforrások meghatározásához. A Bicep-sablonok jobb olvashatóságot, karbantarthatóságot és natív integrációt kínálnak az Azure Resource Managerrel (ARM) a JSON-alapú ARM-sablonokhoz vagy az imperatív szkriptelési módszerekhez, például a PowerShellhez és az Azure CLI-hez képest. Az Azure GitHub Copilotja segíthet Bicep-fájlok létrehozásában.

Bicep-fájlok létrehozása

A Bicep-fájlok használatának első lépéseihez szükség lehet némi tanulásra, ha még csak most ismerkedik a szintaxissal, de az Azure-hoz készült GitHub Copilothoz hasonló eszközök segíthetnek.

Példaforgatókönyv

Tegyük fel, hogy egyszerűen szeretne létrehozni egy megismételhető, automatizált folyamatot egy Blob-tároló és fájlmegosztás létrehozásához. Lehet, hogy ismeri, hogyan hozhat létre Blob-tárolót és fájlmegosztást az Azure Portalon, de nem tudja, hogyan használhatja a Bicep-fájlokat ugyanarra a feladatra.

Példakérés

Hozzon létre egy új csevegést (Ctrl + L), majd másolja és illessze be a következő parancssort a GitHub Copilot csevegőablakába.

Show me a Bicep file that creates an Azure Storage account with a blob container and a file share.

Példa válasz

Megjegyzés

Az alábbi válasz egy példa. Az Azure-beli GitHub Copilot-válaszok nem meghatározhatóak, ezért előfordulhat, hogy az itt láthatótól eltérő választ kap.

Az Azure-hoz készült GitHub Copilot a következőhöz hasonló Bicep-fájlt hoz létre.

@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
  }
}

Hozzon létre egy új main.bicep-fájlt, majd másolja ki a választ az Azure-hoz készült GitHub Copilotból, és illessze be az új fájlba.

Ha az Azure CLI-vel hajtja végre a Bicep-fájlt, beállíthatja a deklarált storageAccountNameparamokat , blobContainerNameés fileShareName.

Másik lehetőségként szerkesztheti a Bicep-fájlt, amely inicializálja a storageAccountName paramot a kívánt értékre.

param storageAccountName string = '<your-storage-account-name>'

A válasz pontosítása

Ha azonban még nem ismerkedik a Bicep-fájlokkal, további információra lehet szüksége. A következő lépések megértéséhez folytassa a kérdezést ugyanabban a csevegési munkamenetben.

Megkérdezheti például, hogy hol kell létrehozni ezt a Bicep-fájlt a VS Code-munkaterületen.

Where in my workspace should I create the Azure Bicep file, and what should I call it?

Az új Bicep-fájl mappájának és fájlnevének javaslatával válaszolhat. Például: infra/storageAccount.bicep.

Végül, ha nem biztos a Bicep-fájl üzembe helyezésében, létrehozhat egy utasítást, amely utasításokat kér.

How do I execute the Azure Bicep file?

Az alábbiakhoz hasonló választ kaphat.

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.

Ha elakad vagy problémát tapasztal ezeknek az utasításoknak a követése közben, folytassa a kérdések feltevését a GitHub Copilotnak, és alakítson ki kérdésbegyűjtéseket, amelyek a azure szót tartalmazzák a csevegőablakban.