Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept "latest" as a valid -i parameter value #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drewmullen
Copy link

@drewmullen drewmullen commented Apr 7, 2023

Thanks for maintaining this script! it works great!

When running this script in another packer build i ran into an issue. When allowing users to optionally set the packer version...

variable "packer_version" {
  type = string
  description = "semver of desired packer version, default is latest"
  default = ""

  validation {
    error_message = "Must be a valid semantic version or \"\" (default)."
    condition     = (
      var.packer_version == "" ||
      can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.packer_version))
    )
  }
}

...
  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }} -i ${var.packer_version}"
    script           = "${path.cwd}/scripts/packer-install.sh"
  }

packer does not output a literal "" and the script errored:

./packer-install.sh -i   
Error - i requires an argument
usage: packer-install.sh [-i VERSION] [-a] [-c] [-h] [-v]
     -i VERSION : specify version to install in format '' (OPTIONAL)
     -a         : automatically use sudo to install to /usr/local/bin
     -c         : leave binary in working directory (for CI/DevOps use)
     -h         : help
     -v         : display packer-install.sh version

Allow setting "latest" OR "" gets around this

When running this script in another packer build i ran into an issue. When allowing users to optionally set the packer version...

```
variable "packer_version" {
  type = string
  description = "semver of desired packer version, default is latest"
  default = ""

  validation {
    error_message = "Must be a valid semantic version or \"\" (default)."
    condition     = (
      var.packer_version == "" ||
      can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.packer_version))
    )
  }
}

...
  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }} -i ${var.packer_version}"
    script           = "${path.cwd}/scripts/packer-install.sh"
  }
```

packer does not output a literal `""` and the script errored:
```
.packer-install.sh -i   
Error - i requires an argument
usage: packer-install.sh [-i VERSION] [-a] [-c] [-h] [-v]
     -i VERSION : specify version to install in format '' (OPTIONAL)
     -a         : automatically use sudo to install to /usr/local/bin
     -c         : leave binary in working directory (for CI/DevOps use)
     -h         : help
     -v         : display packer-install.sh version
```

Allow setting `"latest"` OR `""` gets around this
@drewmullen drewmullen changed the title accept "latest" as a valid -i parameter accept "latest" as a valid -i parameter value Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant