加壳器映像生成器是否创建或使用网络接口和公共 IP(如果是)为什么以及何时?

问题描述 投票:0回答:1

我尝试使用示例打包程序构建来创建映像,但该映像违反了策略网络接口不能拥有公共 IP

错误如下。

” 1 分 33 秒后构建“azure-arm”出错:deployments.DeploymentsClient#Validate:发送请求失败:StatusCode=0 -- 原始错误:代码 =“InvalidTemplateDeployment”消息 =“由于违反策略,模板部署失败。请 查看详细信息以获取更多信息。" 详细信息=[{"additionalInfo":[{"info":{"evaluationDetails":{"evaluatedExpressions":[{"expression":"type","expressionKind":"Field"," expressionValue":"Microsoft.Network/networkInterfaces","operator":"等于","path":"type","res ult":"正确"

请找到如下打包模板

`{ “建设者”:[ { “名称”:“图像”, “类型”:“蔚蓝手臂”,

    "os_disk_size_gb": "256",
    "vm_size": "Standard_F8s_v2",
    "managed_image_storage_account_type": "Standard_LRS",
    
    "client_id": "xxxxxxxxxxxxxxxxxxx",
    "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "tenant_id": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
    "subscription_id": "xxxxxxxxxxxxxxxxxxxxxxxx",
    "object_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",

    "managed_image_name": "mypackerimage",
    "managed_image_resource_group_name": "resource_group_name",
    "build_resource_group_name": "rg",

    "virtual_network_name": "VizDev-AzureDevOps-vnet",
    "virtual_network_resource_group_name": "VizDev-AzureDevOps",
    "virtual_network_subnet_name": "default",

    "os_type": "Windows",
    "image_publisher": "MicrosoftWindowsServer",
    "image_offer": "WindowsServer",
    "image_sku": "2022-Datacenter",
    "communicator": "winrm",
    "winrm_use_ssl": "true",
    "winrm_insecure": "true",
    "winrm_username": "packer"

  }
],
"provisioners": [
  {
    "type": "shell",
    "script": "./provisioning-script.sh"
  },
  {
    "type": "powershell",
    "inline": [
      "Write-Output 'Hello, Packer!'"
    ]
  }
]

}`

windows azure image azure-virtual-network packer
1个回答
0
投票

加壳映像生成器是否创建或使用网络接口和公共 IP(如果是),为什么以及何时?

这取决于您的配置文件中的内容。是的,但是可以定制。请检查文档

virtual_network_name(字符串)- 使用预先存在的虚拟网络 虚拟机。此选项启用与虚拟机的私有通信,无 使用或配置公共 IP 地址(除非您设置 private_virtual_network_with_public_ip).

您必须指定

virtual_network_resource_group_name
virtual_network_name
virtual_network_subnet_name
才能创建没有公共 IP 的虚拟机。

示例:

packer {
  required_plugins {
    azure = {
      source  = "github.com/hashicorp/azure"
      version = "~> 2"
    }
  }
}

source "azure-arm" "linux_build_agent" {
  use_azure_cli_auth = var.use_azure_cli_auth
  subscription_id = var.subscription_id

  build_resource_group_name         = var.build_resource_group_name
  managed_image_resource_group_name = var.managed_image_resource_group_name
  managed_image_name                = var.managed_image_name


  os_type         = var.os_type
  image_publisher = var.source.image_publisher
  image_offer     = var.source.image_offer
  image_sku       = var.source.image_sku

  vm_size = var.vm_size

  azure_tags = {
    "Deployment Type" = "Packer"
  }

  ssh_username = var.user

  virtual_network_resource_group_name = var.networking.virtual_network_resource_group_name
  virtual_network_name                = var.networking.virtual_network_name
  virtual_network_subnet_name         = var.networking.virtual_network_subnet_name

  shared_gallery_image_version_exclude_from_latest = var.shared_gallery_image_version_exclude_from_latest
  shared_image_gallery_destination {
    subscription         = var.destination.gallery_subscription
    resource_group       = var.destination.gallery_resource_group
    gallery_name         = var.destination.gallery_name
    image_name           = var.destination.gallery_image_name
    image_version        = local.image_version
    replication_regions  = var.destination.gallery_replication_regions
    storage_account_type = var.destination.gallery_storage_account_type
  }
}

build {
  name = "linux"
  sources = [
    "source.azure-arm.linux"
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.