次の方法で共有


Copilot を使用して Azure 構成で Terraform を生成する

Copilot は、Azure インフラストラクチャを定義する Terraform 構成を生成するのに役立ちます。 デプロイするインフラストラクチャについて説明すると、Copilot は AzureRM プロバイダーを使用して Terraform 構成を生成します。 構成には、構成がデプロイ可能であることを確認するために、メイン リソースと必要な依存関係の両方が自動的に含まれます。 出力を定義するには、後続のプロンプトを繰り返し実行します。

この記事では、Azure portal から Azure で Copilot を使用し、Visual Studio Code で GitHub Copilot for Azure を使用する方法について説明します。 また、as-is を使用したり、必要に応じて編集したりするためのサンプル Terraform プロンプトも用意されています。

Tip

最良の結果を得るには、プロンプトの長さを制限し、8 種類未満の主要な Terraform リソースを使用してください。 Copilot は、一般的な構成で適切に動作します。 複雑なアーキテクチャや大規模なアーキテクチャでは、不完全な結果や精度の低い結果が得られる場合があります。

Note

Copilot は現在、AzureRM プロバイダー リソースを広範囲にサポートしています。 AzAPI プロバイダーのサポートは進化しており、まだ完全には利用できない可能性があります。 必要なリソースの種類がサポートされていない場合、Copilot はサンプル構造にフォールバックするか、制限事項を説明します。

Azure portal から Azure で Copilot を使用する

  1. Azure Portalを開きます。

  2. 右上隅にある Copilot アイコンを選択します。

    Azure portal の Azure Copilot アイコンのスクリーンショット。

  3. 次の例のように、Terraform 関連のプロンプトを入力します。

    Create a Terraform configuration for a Cognitive Services instance 
    named "mycognitiveservice" and the S0 pricing tier
    
  4. <Enter> キーを押します。

    Azure Copilot プロンプトの例のスクリーンショット。

  5. Azure の Copilot が応答したら、[ フル ビューを開く ] を選択して、構成コード ブロックを全画面表示モードで表示できます。

    Azure portal の Azure Copilot 全画面表示モードのスクリーンショット。

  6. [ コピー ] アイコンを選択して、新しい構成をクリップボードにコピーします。

    Azure Copilot コピー アイコンのスクリーンショット。

  7. コードをエディターに貼り付けます。

Visual Studio Code から GitHub Copilot for Azure を使用する

  1. Visual Studio Code を開きます。

  2. アクティビティ バーから [拡張機能] を選択し、 copilotを検索します。

    ナビゲーション バーの VS Code Extensions アイコンのスクリーンショット。

  3. GitHub Copilot 拡張機能がインストールされていることを確認します。 そうでない場合は、インストールします。

  4. GitHub Copilot Chat 拡張機能がインストールされていることを確認します。 そうでない場合は、インストールします。

  5. [ チャットの切り替え] を選択します。

    VS Code の [Copilot Toggle Chat]\(チャットの切り替え\) オプションのスクリーンショット。

  6. @azureで始まる Terraform 構成のプロンプトを入力します。 たとえば、次のプロンプトでは、さまざまな設定で Content Delivery Network (CDN) リソースが作成されます。

    @azure Use Terraform to create an Azure CDN Front Door profile named "myCDN profile"
    with a custom domain association for "example.com". Configure a CDN Front Door route 
    that links to the default domain, and create a CDN endpoint named "myEndpoint" 
    associated with the custom domain. Ensure that a security policy is applied for 
    enhanced protection in production, and verify that the route is correctly configured
    with the appropriate origin group.
    
  7. <Enter> キーを押します。

    VS Code で Copilot を使用した Terraform 構成プロンプトのスクリーンショット。

  8. GitHub Copilot for Azure では、プロセスを対話形式でガイドし、構成に必要なファイルを作成します。

    VS Code で Copilot によって生成されたファイルのスクリーンショット。

  9. ファイルが作成または更新されると、GitHub Copilot for Azure では、生成された構成に対して terraform init コマンドと terraform validate コマンドを実行できます。

    さまざまな Terraform コマンドを実行する Copilot オプションのスクリーンショット。

サンプルの Terraform プロンプトを確認して使用する

このセクションでは、Terraform 構成の生成に使用できるプロンプトの例をいくつか示します。 シナリオに基づいてこれらのプロンプトを変更するか、他のプロンプトを試してさまざまな種類のクエリを作成します。

Create a Terraform configuration for a Cognitive Services instance with 
name "mycognitiveservice" and S0 pricing tier.
Create a Terraform configuration that deploys a Linux virtual machine 
running Ubuntu 22.04 LTS, with 8 GB of RAM. The virtual machine should 
be located in the West US region and assigned a public IP address. 
It must be connected to a virtual network that includes a subnet and is 
secured by a network security group.
Create a Terraform configuration for a Container App resource named 
"myApp" using the quick start image. Set the container app environment name 
to "awesomeAzureEnv" and the container name to "myQuickStartContainer".
Create a Terraform configuration for an Azure Databricks workspace named 
"myworkspace" with the premium SKU. The workspace should be deployed in 
the West US region.
Create a Terraform configuration for an Azure OpenAI deployment that uses 
the "gpt-4" model. Specify the model version as "2024-05-01-preview" and 
set the deployment name to "myOpenAIModel".

Tip

プロンプトの例については、「Azure で Microsoft Copilot を使用して Terraform と Bicep の構成を生成する」を参照してください。

Next steps