Skip to content

bakefile: mark variables as required #1346

@tnaroska

Description

@tnaroska

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions