2

Azure Resource Managerを使用して1つのキューとイベントハブを配置した既存のサービスバスがあります。Service Busイベントハブ接続文字列の取得

ここで、ServiceBus.dllを使用せずにAzure PowerShellを使用して主キーと接続文字列を取得することに興味があります。出来ますか??

回避策として、既存のリソースを照会して必要な情報を取得するだけで、何も展開しないARMテンプレートを作成しました。

特定のサービス・バスの名前空間のための接続文字列とイベントハブ/キューの主キーを取得するテンプレート以下
{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
     "serviceBusNamespace": { 
      "type": "string", 
      "minLength": 1, 
      "metadata": { 
       "description": "The name of the service bus namespace to create." 
      } 
     }, 
     "resourceName": { 
      "type": "string", 
      "minLength": 1, 
      "metadata": { 
       "description": "The name of the resource to be retreived." 
      } 
     }, 
     "resourceType": { 
      "type": "string", 
      "minLength": 1, 
      "allowedValues": [ 
       "queues", 
       "eventhubs" 
      ], 
      "metadata": { 
       "description": "The type of the resource" 
      } 
     }, 
     "policy": { 
      "type": "string", 
      "minLength": 1, 
      "defaultValue": "ManagePolicy", 
      "allowedValues": [ 
       "ManagePolicy", 
       "SendPolicy", 
       "ListenPolicy" 
      ], 
      "metadata": { 
       "description": "The type of the resource" 
      } 
     } 
    }, 
    "variables": { 
    }, 
    "resources": [ ], 
    "outputs": { 
     "connectionString": { 
      "type": "string", 
      "value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/',parameters('resourceType'),'/authorizationRules'),parameters('serviceBusNamespace'),parameters('resourceName'),parameters('policy')),'2015-08-01').primaryConnectionString]" 
     }, 
     "primaryKey": { 
      "type": "string", 
      "value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/',parameters('resourceType'),'/authorizationRules'),parameters('serviceBusNamespace'),parameters('resourceName'),parameters('policy')),'2015-08-01').primaryKey]" 
     } 
    } 
} 

それはリソースのためクエリにARMのテンプレートを使用して、実際には何も展開しないために悪用されていますか?で定義されととのConnectionStringプロパティ名こと

PowerShell内ARMテンプレートの出力をキャプチャするEDIT

$ep = New-AzureRmResourceGroupDeployment -Name "getEventHub" -ResourceGroupName myResourceGroup -Mode Incremental -TemplateFile getEventHub.json -TemplateParameterFile getEventHub.param.json 
$RuleConnString = $ep.Outputs.connectionString.value 
$RulePrimaryKey = $ep.Outputs.primaryKey.value 

以下のコードを使用注主キーは同じです私のテンプレートファイル

EDIT 2 ARMテンプレートを再実行してイベントハブを2回展開すると、以下のエラーが発生します。 enter image description here

ARMテンプレートを使用して詳細を照会する以外の方法はありません。

答えて

1

これは正しい情報を取得する方法です。リソースマネージャは、すべてのサービスと対話するための共通のインターフェイスを提供します。これはポータルがサービスにアクセスする方法であり、各言語SDKは、作成したものと同様の要求に対する単なるラッパーです。

私は通常、PythonまたはJava SDKを使用していますが、NodeJSは非常に簡単な方法で、ARMが呼び出しているような同様の呼び出しを構築するWeb APIをラップすることができますこれを行うARMの方法。

+0

Node.jsのサンプルがありますか? PowerJhellのNodeJSからの出力を簡単に消費することは可能ですか? – Sandesh

+0

NodeJSはpowershellと混合するのではなく、あなたがやっていることのためのインターフェースやGUIを作ろうと思っていたら。私は何を見つけることができます。 Powershellコマンドレットは、特に「* -azurerm」で始まります。それらは腕のテンプレートとよく混じり合っています –

+0

現在、チームはPowerShellを使用しているオートメーションにのみ焦点を当てています。だから私は今NodeJSが助けになるとは思わない。それまでは私はARMに固執するでしょう。ありがとう:) – Sandesh

2

私は何をしているのか分かりません。私の見解では、Resource Managerテンプレートの性質上、インクリメンタルです。既存のサービスバスを同じリソースで作成するためのテンプレートを作成できます。プロパティが同じ場合、既存のリソースはそのまま残しておき、関連するリソースの接続文字列と主キーを返します。

私は、サービスバスとキューの作成を自動化し、センド/リッスンの共有アクセスポリシーを分離する必要があります。 Get-AzureSBAuthorizationRuleを使用して.Net ServiceBus.dllアセンブリを使用せずにネイティブにPowerShellを使用してサービスバス上の接続文字列を取得することはできますが、現在のバグではキューレベルでは機能しません。

ServiceBus.dllを使用して共有アクセスポリシーを作成しようとしましたが、ランダムに失敗することもありましたが、後でもう一度実行した場合には後で動作します。私もResource Managerテンプレートを試しましたが、以前は自分で生成したキーを渡す必要がありました。今私はMicrosoftがあなたのためにそれらを生成するのを見るが、あなたはまだ自動化された方法でキーを取得しようとしているので、私はあなたのソリューションが好きです。

ただし、Resource Managerテンプレートの出力をキャプチャしてPowerShellスクリプトに戻すことはできますか?

乾杯

ロブ

{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { 
    "servicebusNamespace": { 
     "type": "string", 
     "metadata": { 
     "description": "The service bus namespace" 
     } 
    }, 
    "notificationssmsqueue": { 
     "type": "string", 
     "metadata": { 
     "description": "Notifications SMS queue" 
     } 
    } }, "variables": { 
    "location": "[resourceGroup().location]", }, "resources": [ 
    { 
     "apiVersion": "2015-08-01", 
     "name": "[parameters('servicebusNamespace')]", 
     "type": "Microsoft.ServiceBus/namespaces", 
     "location": "[variables('location')]", 
     "properties": { 
     "messagingSku": 2 
     }, 
     "resources": [ 
     { 
      "apiVersion": "2015-08-01", 
      "name": "[parameters('notificationssmsqueue')]", 
      "type": "Queues", 
      "dependsOn": [ 
      "[concat('Microsoft.ServiceBus/namespaces/', parameters('servicebusNamespace'))]" 
      ], 
      "properties": { 
      "path": "[parameters('notificationssmsqueue')]" 
      }, 
      "resources": [ 
      { 
       "apiVersion": "2015-08-01", 
       "name": "[concat(parameters('notificationssmsqueue'),'.listen')]", 
       "type": "AuthorizationRules", 
       "dependsOn": [ 
       "[parameters('notificationssmsqueue')]" 
       ], 
       "properties": { 
       "keyName": "[concat(parameters('notificationssmsqueue'),'.listen')]", 
       "claimType": "SharedAccessKey", 
       "claimValue": "None", 
       "rights": [ "Listen" ], 
       "revision": -1 
       } 
      }, 
      { 
       "apiVersion": "2015-08-01", 
       "name": "[concat(parameters('notificationssmsqueue'),'.send')]", 
       "type": "AuthorizationRules", 
       "dependsOn": [ 
       "[parameters('notificationssmsqueue')]" 
       ], 
       "properties": { 
       "keyName": "[concat(parameters('notificationssmsqueue'),'.send')]", 
       "claimType": "SharedAccessKey", 
       "claimValue": "None", 
       "rights": [ "Send" ], 
       "revision": -1 
       } 
      } 
      ] 
     } 
     ] 
    } ], "outputs": { 
    "connectionString": { 
     "type": "string", 
     "value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/AuthorizationRules'),parameters('serviceBusNamespace'),'RootManageSharedAccessKey'),'2015-08-01').primaryConnectionString]" 
    }, 
    "smsSendPrimaryKey": { 
     "type": "string", 
     "value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/Queues/AuthorizationRules'),parameters('serviceBusNamespace'),parameters('notificationssmsqueue'),concat(parameters('notificationssmsqueue'),'.send')),'2015-08-01').PrimaryKey]" 
    }, 
    "smsListenPrimaryKey": { 
     "type": "string", 
     "value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/Queues/AuthorizationRules'),parameters('serviceBusNamespace'),parameters('notificationssmsqueue'),concat(parameters('notificationssmsqueue'),'.listen')),'2015-08-01').PrimaryKey]" 
    } } } 

しかし、私は私のテンプレートは次のように呼び出す:

新AzureRMResourceGroupDeployment -ResourceGroupName $ ResourceGroupName -templatefile "$ $ SB_create_script scripts_folder" -TemplateParameterObject ` @ { servicebusNamespace = $ servicebusNamespace; notificationssmsqueue = $ NotificationSMSqueue

+0

ARMテンプレートを再実行してサービスバスと共有アクセスポリシーを再配布すると、エラーが発生してpowershellが失敗します。だから私は選択したテンプレートを使用して投稿した。私が推測するRM配備リソースに対してGet-AzureSBAuthorizationRuleは機能しません。 PSでARMの出力をキャプチャすることができるかどうかについての簡単な答えは***です*** – Sandesh

+0

元のテンプレートを変更して出力を追加して再実行してみませんか?私は、サービスバスを作成し、アクセスポリシーを共有し、出力を追加したテンプレートを用意しています。再実行しても問題なくキーを返すことができます。あなたが好きなら、それを分かち合うのが楽しい? PowerShellで使用するために、どのようにARMテンプレートの出力をキャプチャするのですか?それは欠けているビットです。 –

+0

質問を、ARMテンプレートの出力を読み取る方法を示すコードで更新しました。 – Sandesh