azuretest-kitchenkitchen-azurerm

How to tell Test Kitchen to use a Shared Image Gallery image from Azure?


I am using Test Kitchen with the kitchen-azurerm driver to test my Chef code and am writing a configuration for testing my code against various Azure configurations. One such case is I must make sure my code converges correctly on our "golden" images we have prepared for use at my company. For the battery of tests we run against builds using Microsoft's image SKUs, the solution is simple: use image_urn along with the URN to the image in the Marketplace. Unfortunately, this doesn't work for images not available on the Marketplace.

Given the above, I am unable to use MyCompanyName:MyOffer:MyImageSku:latest with image_urn. I thought to perhaps try working around it with image_url but I don't know what the URL to the VHD file used by the image definition version would be. This also has the detriment of not being able to grab the latest image; unless I am mistaken, I would need to update the URL in kitchen.yml every time I deploy a new image version.


How can I use the kitchen-azurerm driver to consume image definitions from a Shared Image Gallery?


Solution

  • As it turns out, there is another property for use with the azurerm driver called image_id. This should be a Resource ID to a managed machine image. I did some testing and found this works in the following scenarios:

    1. You have direct access to the managed image itself (e.g. not going through the Shared Image Gallery). In this case, provide the resource ID directly associated with the managed image.
    2. You have access to the image via a Shared Image Gallery. You can't use image_urn to search for the an image version, but you can use one of the following resource IDs for the value of image_id
      • Resource ID for a specific image version
        • e.g. /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Compute/galleries/GALLERY_NAME/images/IMAGE_DEFINITION_NAME/versions/IMAGE_VERSION
      • Resource ID for the image definition itself, which grabs latest
        • e.g. /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Compute/galleries/GALLERY_NAME/images/IMAGE_DEFINITION_NAME
        • Note that this is identical to the version-specific example ID, but without the trailing /versions/IMAGE_VERSION

    I am able to consume my Shared Gallery images using any of the techniques above.