Azure용 GitHub Copilot를 사용하여 Bicep 파일 생성

Azure에서 새 리소스를 만드는 방법에는 여러 가지가 있습니다. Bicep 파일은 Azure 리소스를 정의하는 선언적이고 모듈식이며 재사용 가능한 접근 방식을 제공합니다. Bicep 템플릿은 JSON 기반 ARM 템플릿 또는 PowerShell 및 Azure CLI와 같은 명령적 스크립팅 방법에 비해 향상된 가독성, 유지 관리 효율성 및 ARM(Azure Resource Manager)과의 네이티브 통합을 제공합니다. Azure용 GitHub Copilot는 Bicep 파일을 만드는 데 도움이 될 수 있습니다.

Bicep 파일 생성

Bicep 파일을 처음 다루는 경우 구문에 대한 약간의 학습이 필요할 수 있지만, Azure용 GitHub Copilot과 같은 도구가 도움을 줄 수 있습니다.

예제 시나리오

Blob 컨테이너 및 파일 공유를 만들기 위한 반복 가능하고 자동화된 프로세스를 쉽게 만들려는 경우를 가정해 보겠습니다. Azure Portal을 사용하여 Blob 컨테이너 및 파일 공유를 만드는 방법을 잘 알고 있지만 Bicep 파일을 사용하여 동일한 작업을 수행하는 방법을 잘 모릅니다.

예시 프롬프트

새 채팅을 만든 다음(Ctrl+ L), 다음 프롬프트를 복사하여 GitHub Copilot의 채팅 창에 붙여넣습니다.

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

응답 예제

비고

다음 응답이 예제입니다. Azure 응답에 대한 GitHub Copilot는 비결정적이므로 여기에 표시된 것과 다른 응답을 얻을 수 있습니다.

Azure용 GitHub Copilot는 다음과 유사한 Bicep 파일을 생성합니다.

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

새 main.bicep 파일을 만든 다음, Azure용 GitHub Copilot의 응답을 복사하여 새 파일에 붙여넣습니다.

Azure CLI를 사용하여 Bicep 파일을 실행하는 경우 선언된 storageAccountNameblobContainerNamefileShareName매개 변수를 설정할 수 있습니다.

또는 원하는 값으로 매개 변수를 초기화하는 storageAccountName Bicep 파일을 편집할 수 있습니다.

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

응답 구체화

그러나 Bicep 파일을 새로 사용하는 경우 자세한 정보가 필요할 수 있습니다. 동일한 채팅 세션에서 다음 단계를 이해하라는 메시지를 계속 표시합니다.

예를 들어 VS Code 작업 영역에서 이 Bicep 파일을 만들어야 하는 위치를 물어볼 수 있습니다.

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

새 Bicep 파일의 폴더 및 파일 이름을 제안하여 응답할 수 있습니다. 예: infra/storageAccount.bicep.

마지막으로 Bicep 파일을 배포하는 방법을 잘 모르는 경우 지침을 요청하는 프롬프트를 만들 수 있습니다.

How do I execute the Azure Bicep file?

다음과 유사한 응답을 받을 수 있습니다.

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.

이러한 지침을 따르다가 문제가 발생하면, GitHub Copilot에 계속 질문하여 azure를 포함한 프롬프트를 채팅 창에 만드세요.