Cian
Cian

Reputation: 43

Azure Packer - Parameter 'osProfile' is not allowed when building from custom managed image as base

Error:

Build 'azure-arm.centos-base' errored after 14 minutes 1 second: Code="DeploymentFailed" Message="At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details." Details=[{"code":"BadRequest","message":"{\r\n  \"error\": {\r\n    \"code\": \"InvalidParameter\",\r\n    \"message\": \"Parameter 'osProfile' is not allowed.\",\r\n    \"target\": \"osProfile\"\r\n  }\r\n}"}]

Code: Please see packer template (1)

Description: I am attempting to take a managed custom image which was created using the azure cli (2) and use it as my base image in packer. But I am getting the above Error on osProfile. I believe this is because I am using a ‘specialized’ type of image which already has ssh and authentication configured on the box and will NOT allow packer to specify a new username or password. To get around this I have tried to reuse an existing user build into the image as ‘ssh_username’ with ‘ssh_certificate_file’ but the Error is not resolved. Please let me know if there is any other information I can provide!

(1) template.pkr.hcl

source "azure-arm" "centos-base" {
  use_azure_cli_auth = true
  temp_resource_group_name = "dev-packer"
  location = "East US"
  os_type = "Linux"
  ssh_certificate_file = "~/.ssh/<existing_user_key>"
  ssh_username = "<existing_user>"

  managed_image_name = "centos-base-test"
  managed_image_resource_group_name = "***"
  vm_size = "Standard_B2s"

  shared_image_gallery {
    subscription   = "***"
    resource_group = "***"
    gallery_name   = "***"
    image_name     = "centos-base"
    image_version  = "1.0.1"
  }

  shared_image_gallery_destination {
    subscription         = "***"
    resource_group       = "***"
    gallery_name         = "***"
    image_name           = "testingIT"
    image_version        = "1.0.0"
    replication_regions  = ["East US"]
    storage_account_type = "Standard_LRS"
  }
}

build {
  sources = ["source.azure-arm.centos-base"]
  provisioner "shell" {
    execute_command = "sudo -S env {{ .Vars }} {{ .Path }}" # Runs commands as root
    inline = [
      "mkdir -p /var/this/is/a/test",
      "yum upgrade -y"
    ]
    only = ["source.azure-arm.centos-base"]
  }
}

(2) Initial image create

az sig image-version create \
   --resource-group *** \
   --gallery-name *** \
   --gallery-image-definition *** \
   --gallery-image-version *** \
   --target-regions "***" "***" \
   --replica-count 1 \
   --managed-image "<my_VM>"

I am a beginner with Packer so please let me know if I have missed something in my explanation or if there is any simple way around this issue.

Upvotes: 0

Views: 367

Answers (0)

Related Questions