/images/avatar.webp

mrtn.me

Managing Azure VM Disks and Extensions with Terraform: Handling Dependency and State Removal

When managing Azure Virtual Machines (VMs) with Terraform, especially Windows VMs with extensions and attached data disks, it’s common to encounter challenges around the order of resource destruction and avoiding unnecessary delays. This post summarizes practical solutions to these issues, with example commands and configuration snippets derived from a real-world scenario.

The Problem: Terraform Deletes Extensions and Disks Before the VM

By default, Terraform tracks each Azure VM extension (azurerm_virtual_machine_extension) and each data disk attachment (azurerm_virtual_machine_data_disk_attachment) as independent resources. When running terraform destroy, Terraform deletes these extensions and disk attachments one by one before deleting the VM.

Debugging a failing OpenStack image

The problem

On my alpine-openstack-vm project, There is a CI process producing a VM image for OpenStack. The process involves testing that the machine boots. The test fails, but the machine is actually booted. What doesn’t work is the ssh access. As the machine can only be reached via SSH with a private key for obvious security reasons, not having access prevents proper debug.

The objective

The objective is to be able to run the produced VM locally to assess the issue. As the image in its current form doesn’t work, the VM image needs to be slightly modified in order to allow access. If the VM is run locally, adding a root password should be sufficient.

Multiple Docker environments on Windows

On Windows and docker platforms, your docker environment tends to get messy as time goes by.

You can start over from a clean sheet with docker system prune --all but sometimes you would like to keep some images around. This post shows how to set up multiple docker environments on Windows with the help of WSL2 (Windows Subsystem For Linux) and Alpine.

How it works

The idea is to run docker on WSL and use a docker alias on the windows side to invoke the docker command in the WSL distribution. This is a well-known usage pattern with or without Docker desktop.

Useful Python packages discovery sites

Python is an awesome language with an awesome ecosystem. It is both mature and very active. You are rarely left alone when you need to be doing something new. There are always one or more open source libraries or framework to help you achieve your goal.

But now you’re left with a dilemma: Which one to choose ?

The criteria are fairly simple. You want a library actively used and maintained, with the biggest community possible. But you want also a library still having momentum. You don’t want to invest too much is a technology on the downward slope. Without offense, people still doing Struts or ActionScript know what I mean.

Checking Google Play Signatures on .Net

With In-App Billing on Android, each time a purchase occurs, your application receives a JSON payload containing information about the purchase, as well as its signature with your developer certificate.

Google encourages you to verify that the signature is valid to authentify the purchase. You can do that inside the application, but if the delivery of the purchase involves a server, it is better to do it on the server to prevent client code manipulation. The following show how to do it on .Net server application.

Mirror a Git Repository Through Ssh

Redmine can show the timeline of a Git repository but this repository needs to be local (see here). When you host your repository externally (on GitHub, for instance), you need to synchronize your remote repository on your Redmine server.

The following shell script is an All in one command that can be easily put in the crontab to mirror the repository on your Redmine server :

#!/bin/sh


if [ "run" != "$1" ]; then
  exec ssh -i "$GIT_KEY" -o "StrictHostKeyChecking no" "$@"
fi

remote=$2
local=$3

echo "Mirroring from $remote to $local"

name=$(basename "$local")

export GIT_KEY="`mktemp /tmp/git.XXXXXX`"
export GIT_SSH="$0"

cat >"$GIT_KEY" <<EOF
-----BEGIN DSA PRIVATE KEY-----
### Put here your private key ###
-----END DSA PRIVATE KEY-----
EOF

if [ -d "$local" ]; then
        git "--git-dir=$local" remote update
else
        git clone --mirror "$remote" "$local"
fi

rm -f "$GIT_KEY"

exit 0

You need to copy the private key in the script (line 20). You can then use the script with the following syntax