hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
14.98k stars 3.33k forks source link

Please add support to alltrue function #13073

Open luckeyca opened 1 week ago

luckeyca commented 1 week ago

Community Note

Please search the existing issues for relevant feature requests, and use the reaction feature (https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to add upvotes to pre-existing requests.

Description

In HCL2 syntax template, please support alltrue function

Use Case(s)

This is the same as in terraform to be used for variable validation.

Potential configuration

  validation {
    condition = alltrue([for k, v in var.base_image_filter :
      (k == "base_image_compartment_id" && startswith(v, "ocid1.tenancy.oc1..")) ||
      (k == "operating_system" && contains(["Canonical Ubuntu", "Oracle Linux", "Windows"], v)) ||
      (k == "operating_system_version" && contains(["22.04", "8", "9", "Server 2019 Standard", "Server 2022 Standard"], v)) ||
      (k == "display_name_search" && can(regex("^Canonical-Ubuntu-22\\.04-2[0-9][0-9][0-9]\\.\\d+", v))) ||
      (k == "display_name_search" && can(regex("^Oracle-Linux-8\\.\\d-2[0-9][0-9][0-9]\\.\\d+", v))) ||
      (k == "display_name_search" && can(regex("^Oracle-Linux-9\\.\\d-2[0-9][0-9][0-9]\\.\\d+", v))) ||
      (k == "display_name_search" && can(regex("^Windows-Server-2019-Standard-Edition-VM-2[0-9][0-9][0-9]\\.\\d+", v))) ||
      (k == "display_name_search" && can(regex("^Windows-Server-2022-Standard-Edition-VM-2[0-9][0-9][0-9]\\.\\d+", v)))
    ])
    error_message = "Source image search criteria must have the correct keys and values. See base_image_filter variable definition for details."
  }

Potential References