Azure リソース マネージャーでの Azure PowerShell の使用のサンプルを自分でもやってみました。
https://azure.microsoft.com/ja-jp/documentation/articles/powershell-azure-resource-manager/
これをやるために、前回、Azure Powershell 1.00のインストールをしました。
が、すでに1.0.1が出たらしいので、前回の手順を再実行しました。。。。
[Get-Module の実行結果]
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.1 Azure {Add-AzureAccount, Add-AzureApplicationGatewaySslCertifi...
Script 1.0.2 AzureRM {CheckIncompatibleVersion, Import-AzureRM, Install-Modul...
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-C...
Manifest 3.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString, Get-A...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Pac...
Script 1.0 PowerShellGet {Find-Module, Get-InstalledModule, Get-PSRepository, Ins...
Script 1.1 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-...
サンプルで作成する環境
サンプルで作成しているのをざっくりまとめると、下記となります。
- リソースグループの作成
(PowerShell で作成) - 作成したリソースグループに、Web App と SQL Database の作成
(PowerShellからJSONファイルを読み込んで作成)

手順
まずは、ARM で、ログインします。
ログインには、「Login-AzureRmAccount」を実行します。
いつものログイン画面が出てきて認証に成功すると、下記のようなログとなります。
PS C:Windowssystem32> Login-AzureRmAccount Environment : AzureCloud Account : (アカウント名) TenantId : (テナントID) SubscriptionId : (サブスクリプションID) CurrentStorageAccount :
次に、リソースグループを作成します。
PS C:Windowssystem32> New-AzureRmResourceGroup -Name (リソースグループ名) -Location "(リージョン名)" ResourceGroupName : testrsg01 Location : japaneast ProvisioningState : Succeeded Tags : ResourceId : (リソースID)
最後に、作成したリソースグループにJSONファイルに構成したサービスを作成します。
途中でアプリケーションホスティングプラン、SQL Databaseの乗っかるサーバ名と認証情報、SQL Database 名と、いくつかの入力を行っています。
PS C:Windowssystem32> New-AzureRmResourceGroupDeployment -ResourceGroupName (リソースグループ名) -TemplateFile (JSONファイルのフルパス) コマンド パイプライン位置 1 のコマンドレット New-AzureRmResourceGroupDeployment 次のパラメーターに値を指定してください: (ヘルプを表示するには、「!?」と入力してください。) hostingPlanName: y9hostplan01 serverName: y9sv01 databaseName: y9db01 administratorLogin: svadmin administratorLoginPassword: ******** DeploymentName : azuredeploy ResourceGroupName : y0testrsg01 ProvisioningState : Succeeded Timestamp : 2015/11/16 21:34:08 Mode : Incremental TemplateLink : Parameters : Name Type Value =============== ========================= ========== hostingPlanName String y9hostplan01 serverName String y9sv01 databaseName String y9db01 administratorLogin String svadmin administratorLoginPassword SecureString Outputs :
JSONファイルは、そのまま使用しました。
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"hostingPlanName": {
"type": "string"
},
"serverName": {
"type": "string"
},
"databaseName": {
"type": "string"
},
"administratorLogin": {
"type": "string"
},
"administratorLoginPassword": {
"type": "securestring"
}
},
"variables": {
"siteName": "[concat('ExampleSite', uniqueString(resourceGroup().id))]"
},
"resources": [
{
"name": "[parameters('serverName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01",
"properties": {
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]",
"version": "12.0"
},
"resources": [
{
"name": "[parameters('databaseName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01",
"dependsOn": [
"[concat('Microsoft.Sql/servers/', parameters('serverName'))]"
],
"properties": {
"edition": "Basic",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "Basic"
}
},
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01",
"dependsOn": [
"[concat('Microsoft.Sql/servers/', parameters('serverName'))]"
],
"properties": {
"endIpAddress": "0.0.0.0",
"startIpAddress": "0.0.0.0"
}
}
]
},
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/serverfarms",
"name": "[parameters('hostingPlanName')]",
"location": "[resourceGroup().location]",
"sku": {
"tier": "Free",
"name": "f1",
"capacity": 0
},
"properties": {
"numberOfWorkers": 1
}
},
{
"apiVersion": "2015-08-01",
"name": "[variables('siteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Web/serverFarms/', parameters('hostingPlanName'))]"
],
"properties": {
"serverFarmId": "[parameters('hostingPlanName')]"
},
"resources": [
{
"name": "web",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', variables('siteName'))]"
],
"properties": {
"connectionStrings": [
{
"ConnectionString": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', parameters('serverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', parameters('databaseName'), ';User Id=', parameters('administratorLogin'), '@', parameters('serverName'), ';Password=', parameters('administratorLoginPassword'), ';')]",
"Name": "DefaultConnection",
"Type": 2
}
]
}
}
]
}
]
}
まとめ
ひとまず、JSONファイルからサービスをデプロイできました。
これで、スーパー初級編はできたの思うので、もうちょっと応用的な使い方を考えてみよっと〜。


コメント