0

I want to provision an Azure VM with Terraform and configure it by using a custom AMI created by Packer.

I want an attached, snapshotted, managed data-disk.

I want to use Oracle Linux 7.4

What is the best way of

  1. Ensuring the data-disk is mounted on startup
  2. Ensuring that the data-disk is formatted before I attempt to mount it, perhaps formatting it on startup

It's likely I'll be bringing up a cluster of identical machines each with attached data-disks, so ssh-ing in after the fact is not feasible.

Feenaboccles
  • 101
  • 1
  • 1

2 Answers2

1

Firstly, you could not attach a snapshot to a VM, Azure does not support this.

You could attach an existing managed data disk to a VM, you could check this example.

storage_data_disk {
    name            = "${data.azurerm_managed_disk.datasourcemd.name}"
    managed_disk_id = "${data.azurerm_managed_disk.datasourcemd.id}"
    create_option   = "Attach"
    lun             = 1
    disk_size_gb    = "${data.azurerm_managed_disk.datasourcemd.disk_size_gb}"
  }

It's likely I'll be bringing up a cluster of identical machines each with attached data-disks, so ssh-ing in after the fact is not feasible.

You could use Azure Custom Script Extension to do this, you need write a script to mount disk on your VM, then use custom script extension to execute this script.

Another way you could use remote-exec to do this, check this answer.

Shui shengbao
  • 3,583
  • 1
  • 11
  • 20
  • When I say "data-disk" I mean a managed disk which is attached to a VM. Your script creates an unformatted disk, and attaches it to a VM without mounting it. The question is (1) what is the best way to subsequently mount it and (2) what is the best way to ensure it's formatted. For example, should it be created as a `Copy` of an empty formatted disk image? – Feenaboccles Apr 11 '18 at 08:37
  • Thanks for you reply. It is possible. You could use terrafrom to do this. – Shui shengbao Apr 11 '18 at 08:39
0

Creating the disk and attaching it to the VM can be achieved with Terraform.

For actually mounting and formatting it, this needs to occur inside the VM, so you could look at running something using the custom script extension or you could look at configuration management tools like Puppet, Chef, Ansible etc.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
  • Old question, but... See my ansible script for this: https://gist.github.com/marcelboldt/a1a5ac43445675b590eea96c7adde7e0 – Marcel Boldt Sep 08 '22 at 17:35