Official

»Azure DevTest Lab Builder

Type: azure-dtl Artifact BuilderId: Azure.ResourceManagement.VMImage

The Azure DevTest Labs builder builds custom images and uploads them to an existing DevTest Lab image repository automatically. For more information on crating an Azure DevTest Lab see the Configuring a Lab How-to guide.

»Configuration Reference

There are many configuration options available for the builder. We'll start with authentication parameters, then go over the Azure ARM builder specific options. In addition to the options listed here, a communicator can be configured for this builder.

»Authentication options

Config allows for various ways to authenticate Azure clients. When client_id and subscription_id are specified, Packer will use the specified Azure Active Directory (AAD) Service Principal (SP). If only subscription_id is specified, Packer will try to interactively log on the current user (tokens will be cached). If none of these options are specified, Packer will attempt to use the Managed Identity and subscription of the VM that Packer is running on. This will only work if Packer is running on an Azure VM.

»Managed Identity

If you're running Packer on an Azure VM with a managed identity you don't need to specify any additional configuration options. As Packer will attempt to use the Managed Identity and subscription of the VM that Packer is running on.

»Interactive User Authentication

To use interactive user authentication, you should specify subscription_id only. Packer will use cached credentials or redirect you to a website to log in.

»Service Principal

To use a service principal you should specify subscription_id, client_id and one of client_secret, client_cert_path or client_jwt.

  • subscription_id (string) - Subscription under which the build will be performed. The service principal specified in client_id must have full access to this subscription, unless build_resource_group_name option is specified in which case it needs to have owner access to the existing resource group specified in build_resource_group_name parameter.

  • client_id (string) - The Active Directory service principal associated with your builder.

  • client_secret (string) - The password or secret for your service principal.

  • client_cert_path (string) - The location of a PEM file containing a certificate and private key for service principal.

  • client_cert_token_timeout (duration string | ex: "1h30m12s") - How long to set the expire time on the token created when using client_cert_path.

  • client_jwt (string) - The bearer JWT assertion signed using a certificate associated with your service principal principal. See Azure Active Directory docs for more information.

»Azure DevTest Labs builder specific options

»Required:

  • managed_image_resource_group_name (string) - Specify the managed image resource group name where the result of the Packer build will be saved. The resource group must already exist. If this value is set, the value managed_image_name must also be set. See documentation to learn more about managed images.

  • managed_image_name (string) - Specify the managed image name where the result of the Packer build will be saved. The image name must not exist ahead of time, and will not be overwritten. If this value is set, the value managed_image_resource_group_name must also be set. See documentation to learn more about managed images.

  • lab_name (string) - Name of the existing lab where the virtual machine will be created.

  • lab_subnet_name (string) - Name of the subnet being used in the lab, if not the default.

  • lab_resource_group_name (string) - Name of the resource group where the lab exist.

»Optional:

  • capture_name_prefix (string) - Capture

  • capture_container_name (string) - Capture Container Name

  • shared_image_gallery (SharedImageGallery) - Use a Shared Gallery image as the source for this build. VHD targets are incompatible with this build type - the target must be a Managed Image.

  • shared_image_gallery_destination (SharedImageGalleryDestination) - The name of the Shared Image Gallery under which the managed image will be published as Shared Gallery Image version.

    Following is an example.

  • shared_image_gallery_timeout (duration string | ex: "1h5m2s") - How long to wait for an image to be published to the shared image gallery before timing out. If your Packer build is failing on the Publishing to Shared Image Gallery step with the error Original Error: context deadline exceeded, but the image is present when you check your Azure dashboard, then you probably need to increase this timeout from its default of "60m" (valid time units include s for seconds, m for minutes, and h for hours.)

  • custom_image_capture_timeout (duration string | ex: "1h5m2s") - How long to wait for an image to be captured before timing out If your Packer build is failing on the Capture Image step with the error Original Error: context deadline exceeded, but the image is present when you check your custom image repository, then you probably need to increase this timeout from its default of "30m" (valid time units include s for seconds, m for minutes, and h for hours.)

  • image_publisher (string) - PublisherName for your base image. See documentation for details.

    CLI example az vm image list-publishers --location westus

  • image_offer (string) - Offer for your base image. See documentation for details.

    CLI example az vm image list-offers --location westus --publisher Canonical

  • image_sku (string) - SKU for your base image. See documentation for details.

    CLI example az vm image list-skus --location westus --publisher Canonical --offer UbuntuServer

  • image_version (string) - Specify a specific version of an OS to boot from. Defaults to latest. There may be a difference in versions available across regions due to image synchronization latency. To ensure a consistent version across regions set this value to one that is available in all regions where you are deploying.

    CLI example az vm image list --location westus --publisher Canonical --offer UbuntuServer --sku 16.04.0-LTS --all

  • image_url (string) - Specify a custom VHD to use. If this value is set, do not set image_publisher, image_offer, image_sku, or image_version.

  • custom_managed_image_resource_group_name (string) - Specify the source managed image's resource group used to use. If this value is set, do not set image_publisher, image_offer, image_sku, or image_version. If this value is set, the value custom_managed_image_name must also be set. See documentation to learn more about managed images.

  • custom_managed_image_name (string) - Specify the source managed image's name to use. If this value is set, do not set image_publisher, image_offer, image_sku, or image_version. If this value is set, the value custom_managed_image_resource_group_name must also be set. See documentation to learn more about managed images.

  • location (string) - Location

  • vm_size (string) - Size of the VM used for building. This can be changed when you deploy a VM from your VHD. See pricing information. Defaults to Standard_A1.

    CLI example az vm list-sizes --location westus

  • managed_image_storage_account_type (string) - Specify the storage account type for a managed image. Valid values are Standard_LRS and Premium_LRS. The default is Standard_LRS.

  • azure_tags (map[string]*string) - the user can define up to 15 tags. Tag names cannot exceed 512 characters, and tag values cannot exceed 256 characters. Tags are applied to every resource deployed by a Packer build, i.e. Resource Group, VM, NIC, VNET, Public IP, KeyVault, etc.

  • plan_id (string) - Used for creating images from Marketplace images. Please refer to Deploy an image with Marketplace terms for more details. Not all Marketplace images support programmatic deployment, and support is controlled by the image publisher. Plan_id is a string with unique identifier for the plan associated with images. Ex plan_id="1-12ab"

  • polling_duration_timeout (duration string | ex: "1h5m2s") - The default PollingDuration for azure is 15mins, this property will override that value. See Azure DefaultPollingDuration If your Packer build is failing on the ARM deployment step with the error Original Error: context deadline exceeded, then you probably need to increase this timeout from its default of "15m" (valid time units include s for seconds, m for minutes, and h for hours.)

  • os_type (string) - If either Linux or Windows is specified Packer will automatically configure authentication credentials for the provisioned machine. For Linux this configures an SSH authorized key. For Windows this configures a WinRM certificate.

  • os_disk_size_gb (int32) - Specify the size of the OS disk in GB (gigabytes). Values of zero or less than zero are ignored.

  • disk_additional_size ([]int32) - For Managed build the final artifacts are included in the managed image. The additional disk will have the same storage account type as the OS disk, as specified with the managed_image_storage_account_type setting.

  • disk_caching_type (string) - Specify the disk caching type. Valid values are None, ReadOnly, and ReadWrite. The default value is ReadWrite.

  • storage_type (string) - DTL values

  • lab_virtual_network_name (string) - Name of the virtual network used for communicating with the lab vms.

  • dtl_artifacts ([]DtlArtifact) - One or more Artifacts that should be added to the VM at start.

  • vm_name (string) - Name for the virtual machine within the DevTest lab.

  • disallow_public_ip (bool) - DisallowPublicIPAddress - Indicates whether the virtual machine is to be created without a public IP address.

»DtlArtifact

»ArtifactParmater

»Basic Example

variable "client_id" {
  type    = string
  default = "${env("ARM_CLIENT_ID")}"
}

variable "client_secret" {
  type    = string
  default = "${env("ARM_CLIENT_SECRET")}"
}

variable "subscription_id" {
  type    = string
  default = "${env("ARM_SUBSCRIPTION_ID")}"
}

locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

source "azure-dtl" "example" {
  subscription_id                   = "${var.subscription_id}"
  client_id          = "${var.client_id}"
  client_secret      = "${var.client_secret}"
  disallow_public_ip = true
  dtl_artifacts {
    artifact_name = "linux-apt-package"
    parameters {
      name  = "packages"
      value = "vim"
    }
    parameters {
      name  = "update"
      value = "true"
    }
    parameters {
      name  = "options"
      value = "--fix-broken"
    }
  }
  image_offer                       = "UbuntuServer"
  image_publisher                   = "Canonical"
  image_sku                         = "16.04-LTS"
  lab_name                          = "packer-test"
  lab_resource_group_name           = "packer-test"
  lab_virtual_network_name          = "dtlpacker-test"
  location                          = "South Central US"
  managed_image_name                = "ManagedDiskLinux-${local.timestamp}"
  managed_image_resource_group_name = "packer-test"
  os_type                           = "Linux"
  vm_size                           = "Standard_DS2_v2"
}

build {
  sources = ["source.azure-dtl.example"]

}

variable "client_id" {  type    = string  default = "${env("ARM_CLIENT_ID")}"}
variable "client_secret" {  type    = string  default = "${env("ARM_CLIENT_SECRET")}"}
variable "subscription_id" {  type    = string  default = "${env("ARM_SUBSCRIPTION_ID")}"}
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
source "azure-dtl" "example" {  subscription_id                   = "${var.subscription_id}"  client_id          = "${var.client_id}"  client_secret      = "${var.client_secret}"  disallow_public_ip = true  dtl_artifacts {    artifact_name = "linux-apt-package"    parameters {      name  = "packages"      value = "vim"    }    parameters {      name  = "update"      value = "true"    }    parameters {      name  = "options"      value = "--fix-broken"    }  }  image_offer                       = "UbuntuServer"  image_publisher                   = "Canonical"  image_sku                         = "16.04-LTS"  lab_name                          = "packer-test"  lab_resource_group_name           = "packer-test"  lab_virtual_network_name          = "dtlpacker-test"  location                          = "South Central US"  managed_image_name                = "ManagedDiskLinux-${local.timestamp}"  managed_image_resource_group_name = "packer-test"  os_type                           = "Linux"  vm_size                           = "Standard_DS2_v2"}
build {  sources = ["source.azure-dtl.example"]
}