Disable SSH via provisioner

Im using Packer to deploy a firewall and after deployment I want to disable SSH. I’ve tested using a provisioner but I get an error when to the connection drops. How do I handle this error?

It comes as no surprise that the connection drops after you disable ssh, since Packer is probably using the SSH communicator to provision the machine.

The way I understand it, unless you

  1. use another communicator to apply the configuration
  2. delay application of the firewall until next reboot

you can’t get around this issue.