0

I use Azure and I would like to use cloud-init to install some software on VM creation.

Here is the content of cloud-init.yml:

#cloud-config

package_update: true
package_upgrade: true

runcmd:
  - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  - apt update
  - apt install -y docker-ce docker-ce-cli containerd.io
  - usermod -aG docker azureuser
  - curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  - chmod +x /usr/local/bin/docker-compose

power_state:
  mode: reboot
  condition: True

And here is the az command I use to create VM:

az vm create \
    --resource-group $GR_NAME \
    --name $VM_NAME \
    --image UbuntuLTS \
    --admin-username azureuser \
    --custom-data cloud-init.yml \
    --generate-ssh-keys

When the above command returns I am able to ssh into machine but my installation process is still running with cloud-init and in fact finishes only after ~3 minutes and the machine reboots.

I expect that VM provisioning should be blocked by cloud-init but it is not. Is it possible to force "blocking" behavior?

1 Answers1

2

All Cloud-Init is doing is running your commands once the VM is running, it does not block anyone from connecting to the machine while it is running and there isn't really a way to do that.

You could look at scripting something that disables RDP access on the NSG until the VM has completed provisioning.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114