Automating Minecraft Bedrock server deployment with Packer has been a fun and useful project for me, but like all automation scripts, it requires occasional maintenance. Recently, I discovered that my existing automation script for setting up Minecraft Bedrock servers on Azure (or any cloud, really) had stopped working. The culprit? Mojang changed the location of the server files and introduced new requirements for downloading them. This small but critical change broke my provisioning workflow, and I needed to adapt.

To ensure that my script continued working, I revisited how I was fetching the latest version of Minecraft Bedrock. Previously, I used a well-known script to determine the latest version and download the appropriate installation package. However, Mojang’s recent update altered the URL structure for downloading the Bedrock server files. Additionally, the request headers now need to be explicitly defined when fetching the files — something that wasn’t necessary before.

Luckily, the headers were already being used when querying for the latest version number, so I extended that logic to the file download step. This update ensures that the provisioning process retrieves the correct package without any manual intervention. Below is the revised provisioner block that now properly fetches and installs the latest Minecraft Bedrock server version:

  provisioner "shell" {
    execute_command = local.execute_command
    inline = [
      "randomint=$(tr -dc 0-9 < /dev/urandom 2>/dev/null | head -c 4 | xargs)",
      "DOWNLOAD_URL=$(curl -H \"Accept-Encoding: identity\" -H \"Accept-Language: en\" -s -L -A \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.$${randomint}.212 Safari/537.36\" https://www.minecraft.net/en-us/download/server/bedrock/ |  grep -o 'https://www.minecraft.net/bedrockdedicatedserver/bin-linux/[^\"]*')",
      "curl -o /home/mcserver/minecraft_bedrock/bedrock-server.zip -H \"Accept-Encoding: identity\" -H \"Accept-Language: en\" -s -L -A \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.$${randomint}.212 Safari/537.36\" \"$DOWNLOAD_URL\"",
      "unzip /home/mcserver/minecraft_bedrock/bedrock-server.zip -d /home/mcserver/minecraft_bedrock/",
      "rm /home/mcserver/minecraft_bedrock/bedrock-server.zip",
      "chown -R mcserver: /home/mcserver/"
      ]
  }

One thing to note is that when using an inline script like this, escaping double quotes is necessary. The core logic remains the same: query for the latest version, download it, extract the files, and ensure proper file ownership. Here’s what the isolated download command looks like:

curl -L -o bedrock-server.zip \
  -H "Accept-Encoding: identity" \
  -H "Accept-Language: en" \
  -s -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.$${randomint}.212 Safari/537.36" \
  "$DOWNLOAD_URL"

With this fix in place, my Packer automation script is back in action, allowing me to spin up Minecraft Bedrock servers seamlessly. If you’re using a similar approach and found that your deployments suddenly stopped working, updating your script to incorporate these changes should get you back on track. Now, I can finally return to what matters most — playing Minecraft!

Alt