ポイント
- Azureでは、AWSでいうAMIスナップショットをとることはできない
- キャプチャという機能でできるんだけど、VMを破棄することになるというのとWindowsの場合Sysprepをかけておかないと再利用ができない
- キャプチャは展開用のイメージを作る感じでバックアップで利用するのは難しい
- VMにアタッチされているルートボリュームのスナップショットを取得しておけばバックアップになる
- terraformで利用する場合は、以下のように、storage_os_diskにdiskを指定し、そのdiskがsnapshotから作榮されるような感じで書く
ソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span class="k">resource</span> <span class="s2">"azurerm_virtual_machine"</span> <span class="s2">"main"</span> <span class="p">{</span> <span class="nx">name</span> <span class="p">=</span> <span class="kd">var</span><span class="p">.</span><span class="nx">web01</span><span class="err">-</span><span class="nx">vmname</span> <span class="nx">location</span> <span class="p">=</span> <span class="kd">var</span><span class="p">.</span><span class="nx">location</span> <span class="nx">resource_group_name</span> <span class="p">=</span> <span class="nx">azurerm_resource_group</span><span class="p">.</span><span class="nx">resource_group</span><span class="p">.</span><span class="nx">name</span> <span class="nx">network_interface_ids</span> <span class="p">=</span> <span class="p">[</span><span class="nx">azurerm_network_interface</span><span class="p">.</span><span class="nx">main</span><span class="p">.</span><span class="nx">id</span><span class="p">]</span> <span class="nx">vm_size</span> <span class="p">=</span> <span class="s2">"Standard_DS1_v2"</span> <span class="nx">storage_os_disk</span> <span class="p">{</span> <span class="nx">name</span> <span class="p">=</span> <span class="nx">azurerm_managed_disk</span><span class="p">.</span><span class="nx">root</span><span class="p">.</span><span class="nx">name</span> <span class="nx">os_type</span> <span class="p">=</span> <span class="s2">"Windows"</span> <span class="nx">managed_disk_id</span> <span class="p">=</span> <span class="nx">azurerm_managed_disk</span><span class="p">.</span><span class="nx">root</span><span class="p">.</span><span class="nx">id</span> <span class="nx">create_option</span> <span class="p">=</span> <span class="s2">"Attach"</span> <span class="p">}</span> <span class="p">}</span> <span class="k">resource</span> <span class="s2">"azurerm_managed_disk"</span> <span class="s2">"root"</span> <span class="p">{</span> <span class="nx">name</span> <span class="p">=</span> <span class="s2">"root"</span> <span class="nx">location</span> <span class="p">=</span> <span class="s2">"japaneast"</span> <span class="nx">resource_group_name</span> <span class="p">=</span> <span class="s2">"backup"</span> <span class="nx">storage_account_type</span> <span class="p">=</span> <span class="s2">"StandardSSD_LRS"</span> <span class="nx">create_option</span> <span class="p">=</span> <span class="s2">"Copy"</span> <span class="nx">source_resource_id</span> <span class="p">=</span> <span class="s2">"/subscriptions/9611116b-ea93-42fc-bc7a-6a1149bb2521/resourceGroups/backup/providers/Microsoft.Compute/snapshots/web-20201005"</span> <span class="p">}</span> |