https://qiita.com/johanburati/items/5f6cccdf6323e6bfe779
https://docs.microsoft.com/ja-jp/azure/virtual-machines/linux/quick-create-powershell
前提:
OS: CentOS7
作業ユーザ: testuser
-- 1. Azure Powershellモジュールのインストール
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
sudo yum install -y powershell
pwsh
Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Connect-AzAccount -UseDeviceAuthentication
-- 2. リソースグループ作成
New-AzResourceGroup `
-Name rg01 `
-Location japaneast
-- 3. インスタンス作成
New-AzVm `
-ResourceGroupName rg01 `
-Name instance-1 `
-Location japaneast `
-Image CentOS `
-size Standard_B1ls `
-PublicIpAddressName ip01 `
-OpenPorts 22 `
-GenerateSshKey `
-SshKeyName sshkey01
-- 4. SSH接続
Get-AzPublicIpAddress -Name ip01 -ResourceGroupName rg01 | select "IpAddress"
chmod 400 /home/testuser/.ssh/9999999999
ssh -i /home/testuser/.ssh/9999999999 testuser@192.0.2.1
※powershellのプロンプトからそのまま実行可能
-- 5. インスタンス停止/起動
Get-AzVM `
-ResourceGroupName rg01
Get-AzVM `
-ResourceGroupName rg01 `
-Name instance-1 `
-Status
Stop-AzVM `
-ResourceGroupName rg01 `
-Name instance-1 `
-Force
Start-AzVM `
-ResourceGroupName rg01 `
-Name instance-1
-- 6. クリーンアップ
-- リソースグループの削除
Get-AzResource
Get-AzResource -ResourceGroupName rg01
Remove-AzResourceGroup rg01 -Force -Verbose
Remove-AzResourceGroup NetworkWatcherRG -Force -Verbose