Azure PowerShell を使用して仮想マシンの Key Vault を設定する

適用対象: ✔️ Linux VM ✔️ Windows VM ✔️ フレキシブル スケール セット

Note

Azure には、リソースの作成と操作に使用できる、Azure Resource Manager およびクラシックという 2 つの異なるデプロイ モデルがあります。 この記事では、Resource Manager デプロイ モデルの使用について説明します。 新しいデプロイには、クラシック デプロイ モデルではなく、Resource Manager デプロイ モデルをお勧めします。

Azure Resource Manager スタックでは、Key Vault のリソース プロバイダーにより提供されるリソースとしてシークレット/証明書がモデル化されます。 Key Vault の詳細については、「 Azure Key Vault とは

注意

  1. Key Vault を Azure Resource Manager 仮想マシンと共に使用するには、Key Vault の EnabledForDeployment プロパティを True に設定する必要があります。 この設定は、さまざまなクライアントで実行できます。
  2. Key Vault は、仮想マシンと同じサブスクリプションと場所に作成する必要があります。

PowerShell を使用して Key Vault を設定する

PowerShell を使用して Key Vault を作成するには、「PowerShell を使用して Azure Key Vault との間でシークレットの設定と取得を行う」を参照してください。

新しい Key Vault の場合は、次の PowerShell コマンドレットを使用することができます。

New-AzKeyVault -VaultName 'ContosoKeyVault' -ResourceGroupName 'ContosoResourceGroup' -Location 'East Asia' -EnabledForDeployment

既存の Key Vault の場合は、次の PowerShell コマンドレットを使用することができます。

Set-AzKeyVaultAccessPolicy -VaultName 'ContosoKeyVault' -EnabledForDeployment

CLI を使用して Key Vault を設定する

コマンド ライン インターフェイス (CLI) を使用して Key Vault を作成するには、「 CLI を使用した Key Vault の管理」を参照してください。

CLI の場合、デプロイ ポリシーを割り当てる前に、Key Vault を作成する必要があります。 この処理には、次のコマンドを使用できます。

az keyvault create --name "ContosoKeyVault" --resource-group "ContosoResourceGroup" --location "EastAsia"

さらに、テンプレートのデプロイで使用するために Key Vault を有効にするには、次のコマンドを実行します。

az keyvault update --name "ContosoKeyVault" --resource-group "ContosoResourceGroup" --enabled-for-deployment "true"

テンプレートを使用して Key Vault を設定する

テンプレートを使用する場合、Key Vault リソースの enabledForDeployment プロパティを true に設定する必要があります。

{
  "type": "Microsoft.KeyVault/vaults",
  "name": "ContosoKeyVault",
  "apiVersion": "2015-06-01",
  "location": "<location-of-key-vault>",
  "properties": {
    "enabledForDeployment": "true",
    ....
    ....
  }
}

テンプレートを使用して、Key Vault の作成時に構成できるその他のオプションについては、「 Create a Key Vault」を参照してください。