Quick Drop Deluxe: Snag Config Files to Parameterize and Include in Your Packer Templates
I was recently setting up Minecraft Dedicated Server Java Edition. Most of my work with Minecraft has been with Bedrock edition which has a similar setup. Both have a server.properties
file but the Java Edition has some different settings that I needed to configure.
I wanted to build these settings into my Packer template so that I can bake an image that allows me to easily swap in new values at runtime. It’s not a super great experience trying to copy and paste from vi
while in an active SSH connection. Therefore, sometimes its handy to drop a file into the Azure Storage account for easier access.
Azure provides a pretty handy feature that allows you to execute a script on the server. This can be done via the Azure Portal so it’s more of a sneakernet type operation.
The below is my first attempt:
az login
if [ ! -f "/home/mcserver/minecraft_java/server.properties" ]; then
echo "File '/home/mcserver/minecraft_java/server.properties' does not exist."
exit 1
fi
az storage blob upload \
--account-name stmc54251059 \
--container-name drop \
--name server.properties \
--file /home/mcserver/minecraft_java/server.properties \
--auth-mode login \
--overwrite
I setup a managed identity on the Virtual Machine which allows the machine to impersonate the identity but you still need to perform an az login
in order to initialize the Azure CLI to perform the upload to Blob Storage. Besides that, I’m just doing a simple check to see if the file exists or not.
From the Virtual Machine, open up the “Run command” under “Operations” and do the following:
- Select linux bash script
- Run the command, and make sure to select “RunShellScript”
I had to modify the az login
command in order to specify the Managed Identity’s identifier. This is a common problem that you’ll encounter when you explicitly set User-Assigned Managed Identities. Because Azure allows a Virtual Machine to have multiple Managed Identities assigned to it, the Operating System doesn’t know which Managed Identity it should use. Therefore, you just need to be explicit. Now this isn’t any reason not to use User-Assigned Managed identities. I only draw your attention to it because it’s a common pitfall. I actually, highly recommend always using User-Assigned Managed Identities.
az login \
--identity \
--username d8102892-32b9-410c-82e5-d76e1cf9b0de
if [ ! -f "/home/mcserver/minecraft_java/server.properties" ]; then
echo "File '/home/mcserver/minecraft_java/server.properties' does not exist."
exit 1
fi
az storage blob upload \
--account-name stmc54251059 \
--container-name drop \
--name server.properties \
--file /home/mcserver/minecraft_java/server.properties \
--auth-mode login \
--overwrite
You’ll notice that I hard coded a lot of the settings in this script–the storage account name, the container name, and the managed identity ID. There is no sense in parameterizing it due to the way I am using the script as a one-time file drop.
I know this article is a little bit on the ClickOps side but it’s a pretty handy way to snag configuration files that you otherwise want to parameterize within your Packer build automation.