首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用一个源同时构建VHD和托管映像。错误“可以生成VHD或托管映像”。

使用一个源同时构建VHD和托管映像。错误“可以生成VHD或托管映像”。
EN

Stack Overflow用户
提问于 2022-09-18 21:10:41
回答 1查看 66关注 0票数 0

我仍然在学习packer,但是我已经能够通过注释出代码的不同部分来开发Managerd和VHD。我如何避免这个错误:

代码语言:javascript
复制
Error: 2 error(s) occurred:

* Either a VHD or a managed image can be built, but not both. Please specify either capture_container_name and capture_name_prefix or managed_image_resource_group_name and managed_image_name.
* Specify either a VHD (storage_account and resource_group_name) or Managed Image (managed_image_resource_group_name and managed_image_name) output

  on windows_server2019.pkr.hcl line 10:
  (source code not available)



==> Wait completed after 0 seconds

==> Builds finished but no artifacts were created.

代码:

代码语言:javascript
复制
packer {
  required_plugins {
    windows-update = {
      version = "0.14.1"
      source  = "github.com/rgl/windows-update"
    }
  }
}

source "azure-arm" "server_2019" {
  use_azure_cli_auth                               = true
  azure_tags                                       = local.tags
  build_resource_group_name                        = var.resource_group_name
  build_key_vault_name                             = "EXAMPLE-RGP-${var.environment}-KVT"
  os_type                                          = local.azure_sku.os_type
  image_publisher                                  = local.azure_sku.image_publisher
  image_offer                                      = local.azure_sku.image_offer
  image_sku                                        = local.azure_sku.image_sku
  vm_size                                          = local.azure_sku.vm_size
  shared_gallery_image_version_exclude_from_latest = false
  virtual_network_resource_group_name              = local.network.virtual_network_resource_group_name
  virtual_network_name                             = local.network.virtual_network_name
  virtual_network_subnet_name                      = local.network.virtual_network_subnet_name
  private_virtual_network_with_public_ip           = false
  communicator                                     = "winrm"
  winrm_use_ssl                                    = true
  winrm_insecure                                   = true
  winrm_timeout                                    = "3m"
  winrm_username                                   = "winrm"
  winrm_password                                   = var.winrm_password

  # VHD (Both VHD and Managed image can't be done at the same time, comment one of them out)
  resource_group_name    = var.resource_group_name
  storage_account        = lower("examplestorage${var.environment}blobevgimg")
  capture_container_name = "evergreen-images"
  capture_name_prefix    = "packer_server2019"

  # Managed Image (Both VHD and Managed image can't be done at the same time, comment one of them out)
  managed_image_name                 = "packer_server2019"
  managed_image_resource_group_name  = var.resource_group_name
  managed_image_storage_account_type = "Standard_LRS"
  shared_image_gallery_destination {
    resource_group       = var.resource_group_name
    gallery_name         = upper("GALLERY${var.environment}EVERGREENIMAGES")
    image_name           = "Evergreen-Images-Windows"
    image_version        = formatdate("YYYY.MM.DD", timestamp())
    replication_regions  = ["australiaeast", "australiasoutheast"]
    storage_account_type = "Standard_ZRS"
  }
}

build {
  sources = [
    "sources.azure-arm.server_2019",
  ]

  provisioner "file" {
    source      = "../scripts/ConfigureRemotingForAnsible.ps1"
    destination = "C:\\temp\\ConfigureRemotingForAnsible.ps1"
  }

  provisioner "windows-update" {
    search_criteria = "IsInstalled=0"
    filters = [
      "exclude:$_.Title -like '*Preview*'",
      "include:$true",
    ]
    update_limit = 25
  }
}

我知道我可以通过拥有一个复杂的独立构建文件并直接从CLI调用它来实现这一点,但是我想知道是否有什么神奇的东西可以让我拥有相同的模板文件并同时构建一个托管映像和VHD?

EN

回答 1

Stack Overflow用户

发布于 2022-09-20 21:08:33

发现我可以使用多个资源并构建每个源。因此,是的,它是有可能建立一个托管映像和vhd。

代码语言:javascript
复制
packer {
  required_plugins {
    windows-update = {
      version = "0.14.1"
      source  = "github.com/rgl/windows-update"
    }
  }
}

source "azure-arm" "server_2019" {
  use_azure_cli_auth                               = true
  azure_tags                                       = local.tags
  build_resource_group_name                        = var.resource_group_name
  build_key_vault_name                             = local.build_key_vault_name
  os_type                                          = local.azure_skus.windows.os_type
  image_publisher                                  = local.azure_skus.windows.image_publisher
  image_offer                                      = local.azure_skus.windows.image_offer
  image_sku                                        = local.azure_skus.windows.image_sku
  vm_size                                          = local.azure_skus.windows.vm_size
  shared_gallery_image_version_exclude_from_latest = false
  virtual_network_resource_group_name              = local.network.virtual_network_resource_group_name
  virtual_network_name                             = local.network.virtual_network_name
  virtual_network_subnet_name                      = local.network.virtual_network_subnet_name
  private_virtual_network_with_public_ip           = false
  communicator                                     = "winrm"
  winrm_use_ssl                                    = true
  winrm_insecure                                   = true
  winrm_timeout                                    = "3m"
  winrm_username                                   = local.login_name
  winrm_password                                   = var.login_password
  managed_image_name                               = local.azure_skus.windows.packer_image_name
  managed_image_resource_group_name                = var.resource_group_name
  managed_image_storage_account_type               = "Standard_LRS"

  shared_image_gallery_destination {
    resource_group       = var.resource_group_name
    gallery_name         = local.gallery_name
    image_name           = local.azure_skus.windows.image_name
    image_version        = formatdate("YYYY.MM.DD", timestamp())
    replication_regions  = ["australiaeast", "australiasoutheast"]
    storage_account_type = "Standard_LRS"
  }
}

source "azure-arm" "server_2019_vhd" {
  use_azure_cli_auth                               = true
  azure_tags                                       = local.tags
  build_resource_group_name                        = var.resource_group_name
  build_key_vault_name                             = local.build_key_vault_name
  os_type                                          = local.azure_skus.windows.os_type
  image_publisher                                  = local.azure_skus.windows.image_publisher
  image_offer                                      = local.azure_skus.windows.image_offer
  image_sku                                        = local.azure_skus.windows.image_sku
  vm_size                                          = local.azure_skus.windows.vm_size
  shared_gallery_image_version_exclude_from_latest = false
  virtual_network_resource_group_name              = local.network.virtual_network_resource_group_name
  virtual_network_name                             = local.network.virtual_network_name
  virtual_network_subnet_name                      = local.network.virtual_network_subnet_name
  private_virtual_network_with_public_ip           = false
  communicator                                     = "winrm"
  winrm_use_ssl                                    = true
  winrm_insecure                                   = true
  winrm_timeout                                    = "3m"
  winrm_username                                   = local.login_name
  winrm_password                                   = var.login_password
  resource_group_name                              = var.resource_group_name
  storage_account                                  = local.storage_account
  capture_container_name                           = "evergreen-images"
  capture_name_prefix                              = local.azure_skus.windows.packer_image_name
}

build {
  sources = [
    "sources.azure-arm.server_2019",
    "sources.azure-arm.server_2019_vhd",
  ]

  provisioner "file" {
    source      = "../../scripts/ConfigureRemotingForAnsible.ps1"
    destination = "C:\\temp\\ConfigureRemotingForAnsible.ps1"
  }

  provisioner "windows-update" {
    search_criteria = "IsInstalled=0"
    filters = [
      "exclude:$_.Title -like '*Preview*'",
      "include:$true",
    ]
    update_limit = 25
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73766422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档