hashicorp/packer · error

the `method` must be one of %v

Error message

the `method` must be one of %v

What it means

The http datasource only permits a fixed set of HTTP methods (allowedMethods: GET, POST, PUT, DELETE, HEAD, PATCH...). If `method` is set to anything else, Configure rejects the config with the allowed list in the message.

Source

Thrown at datasource/http/data.go:86

	// Default to GET if no method is specified
	if d.config.Method == "" {
		d.config.Method = "GET"
	}

	// Check if the input is in the list of allowed methods
	validMethod := false
	allowedMethods := []string{"HEAD", "GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"}
	for _, method := range allowedMethods {
		if method == d.config.Method {
			validMethod = true
			break
		}
	}
	if !validMethod {
		errs = packersdk.MultiErrorAppend(
			errs,
			fmt.Errorf("the `method` must be one of %v", allowedMethods))
	}

	if errs != nil && len(errs.Errors) > 0 {
		return errs
	}
	return nil
}

func (d *Datasource) OutputSpec() hcldec.ObjectSpec {
	return (&DatasourceOutput{}).FlatMapstructure().HCL2Spec()
}

// This is to prevent potential issues w/ binary files
// and generally unprintable characters
// See https://github.com/hashicorp/terraform/pull/3858#issuecomment-156856738
func isContentTypeText(contentType string) bool {

	parsedType, params, err := mime.ParseMediaType(contentType)

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Set `method` to one of the allowed values listed in the error (e.g. GET, POST, PUT, DELETE, HEAD)
  2. Use the exact uppercase spelling from the allowedMethods list
  3. Remove the `method` attribute entirely to default to GET

Example fix

// before
method = "get"
// after
method = "GET"
Defensive patterns

Strategy: validation

Validate before calling

variable "http_method" {
  type = string
  validation { condition = contains(["GET","POST","PUT","DELETE","HEAD"], var.http_method) error_message = "unsupported method" }
}

Prevention

When it happens

Trigger: Setting `method = "get"` (lowercase, if not accepted), "OPTIONS", "TRACE", or any misspelled method in the http datasource block.

Common situations: Users copy curl-like invocations into Packer config, assume case-insensitivity, or try OPTIONS to probe endpoints.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/9c9c3fa75731afb0. Report an issue: GitHub.