Terraform-provider-azurerm: Add support for Image Builder service (VHDs from Packer templates)

Created on 4 Jun 2019  路  3Comments  路  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Add support for the Azure Image Builder service (currently in late preview), to automatically build VHDs (or managed/shared images?) from Packer templates, which can then be used by the azurerm_image or azurerm_shared_image resources.

The goal would be to remove the manual image creation and upload step from the workflow described in Create a private Azure Pipeline Agent using Packer, Terraform and Ansible.

New or Affected Resource(s)

  • azurerm_image
  • azurerm_shared_image
  • azurerm_image_template

Potential Terraform Configuration

resource "azurerm_image_template" "template" {
  # Should some accommodation be made for embedded Packer templates,
  # or uploading to remote storage from local filesystem?
  template_uri = "PACKER_IMAGE_PATH"
}

resource "azurerm_image" "image" {
  source_template_id = "${azurerm_image_template.template.id}"
}

resource "azurerm_virtual_machine" "vm" {
  storage_image_reference {
    id = "${azurerm_image.image.id}"
  }

References

  • Refs https://github.com/terraform-providers/terraform-provider-azurerm/issues/164

  • Refs https://github.com/terraform-providers/terraform-provider-azurerm/issues/1480, may need to implement the remote-exec provisioner implicitly to build the image if necessary when an image template is referenced as a source for an image? (Starting the image build seems to require an explicit invocation.)
  • https://twitter.com/mitchellh/status/1046807264512884736
  • https://docs.microsoft.com/en-us/azure/virtual-machines/windows/image-builder
  • https://docs.microsoft.com/en-us/azure/virtual-machines/linux/image-builder-json?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json
  • https://github.com/Azure/azure-sdk-for-go/tree/master/services/preview/virtualmachineimagebuilder/mgmt/2019-05-01-preview/virtualmachineimagebuilder
  • enhancement servicimages

    All 3 comments

    I'm working on this.

    @mybayern1974 any luck with the progress on this?

    I submitted a PR to support this Azure resource. However I did not think of an elegant way to support the preference the issue raised:

    resource "azurerm_image" "image" {
      source_template_id = azurerm_image_template.template.id
    }
    

    Because:

    1. The output of this resource could be multiple managed images, shared image versions and vhd. To serve the above expectation, only the image builder template that only has one managed image as output could potentially serve.
    2. As what has been pointed out here, provisioning this resource only generated the template resource rather than its actual distribution resources that can only be generated after a RUN action. While those generated resources become out of control of Terraform that just manages this template resource.

    So the current implementation is to have Terraform manage this template resource and leave post execution outside of Terraform.

    Was this page helpful?
    0 / 5 - 0 ratings