hashicorp / packer

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

HCL2 variable validation #10148

Closed azr closed 4 years ago

azr commented 4 years ago

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Allow to validate input variables so that we don't have to wait for a plugin to error to tell us that a a user parameter is incorrect. Also this will allow users to make sure their resources are correctly named in general.

Potential configuration

variable "ami_id" {
  type = string

  validation {
    condition = (
        length(var.ami_id) > 4 &&
        substr(var.ami_id, 0, 4) == "ami-"
    )
    error_message = "The ami_id value must start with \"ami-\"."
  }
}

Potential References

https://www.hashicorp.com/blog/custom-variable-validation-in-terraform-0-13

ghost commented 3 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.