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

bakefile: mark variables as required #1346

Closed
tnaroska opened this issue Oct 5, 2022 · 3 comments · Fixed by #2794
Closed

bakefile: mark variables as required #1346

tnaroska opened this issue Oct 5, 2022 · 3 comments · Fixed by #2794

Comments

@tnaroska
Copy link

tnaroska commented Oct 5, 2022

Current

There seems to be no way in current hcl bakefile syntax to mark a variable as required. There is a way to specify defaults:

# docker-bake.hcl
variable "TAG" {
  default = "latest"
}

Or without explicit default the variable defaults to empty:

# docker-bake.hcl
variable "TAG" {
}

Proposed Enhancement

I'm trying to define a variable that is required to be set by the caller (i.e. through environment variable). Something like:

# docker-bake.hcl
variable "TAG" {
  required = true
}

Where the user needs to specify the tag when executing buildx bake through either env-var or by passing multiple bake files (where the variable needs to be set to a value in at least one of the bake files).

Expectation:

# docker-bake.hcl
variable "TAG" {
  required = true
}


$ buildx bake              # -> error: required variable "TAG" not defined
$ TAG=latest buildx bake   # -> success
@crazy-max
Copy link
Member

Having something as suggested in #491 (comment) with type constraints and validation like terraform does would be more aligned I think:

variable "slugs" {
  type = list(string)
  default = [
    "crazymax/diun",
    "ghcr.io/crazy-max/diun"
  ]
  validation {
    condition = length(var.slugs) > 0
    error_message = "At least one slug is required."
  }
}

@tnaroska
Copy link
Author

tnaroska commented Oct 5, 2022

💯 that would be a nicer, more general approach!

@thompson-shaun
Copy link
Collaborator

We'll move forward with this issue as-is, likely with the suggested modifications from @crazy-max, but we'll keep the work scoped to addressing the required case. Other work items will cover additional cases such as validation and typing.

/cc @crazy-max @tonistiigi @colinhemmings

@thompson-shaun thompson-shaun modified the milestones: v0.future, v0.19.0 Oct 3, 2024
@thompson-shaun thompson-shaun added kind/bug Something isn't working kind/enhancement New feature or request and removed kind/enhancement New feature or request kind/bug Something isn't working labels Oct 8, 2024
@thompson-shaun thompson-shaun modified the milestones: v0.19.0, v0.20.0 Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants