Incidentally the author's suggestions are not that good, and not what I would suggest. He should be waiting for cloud-init to finish, not just apt:
cloud-init status --wait
Before I knew about that, I used the following, which is still better than what the author suggests: while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done
Other stuff happens in cloud-init besides locking apt for awhile, and these will wait for all of it to finish.