gohugoio/hugo · error

origin must be <project>/<origin>

Error message

origin must be <project>/<origin>

What it means

`InvalidateGoogleCloudCDN` (in the `withdeploy` build of Hugo) splits the configured `googleCloudCDNOrigin` string on `/` and requires exactly two parts: the GCP project ID and the URL map/origin name, which it passes to `compute.UrlMaps.InvalidateCache`. Any other shape makes the API call impossible, so it fails fast with this error.

Source

Thrown at deploy/google.go:30

// limitations under the License.

//go:build withdeploy

package deploy

import (
	"context"
	"fmt"
	"strings"

	"google.golang.org/api/compute/v1"
)

// Invalidate all of the content in a Google Cloud CDN distribution.
func InvalidateGoogleCloudCDN(ctx context.Context, origin string) error {
	parts := strings.Split(origin, "/")
	if len(parts) != 2 {
		return fmt.Errorf("origin must be <project>/<origin>")
	}
	service, err := compute.NewService(ctx)
	if err != nil {
		return err
	}
	rule := &compute.CacheInvalidationRule{Path: "/*"}
	_, err = service.UrlMaps.InvalidateCache(parts[0], parts[1], rule).Context(ctx).Do()
	return err
}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Set `googleCloudCDNOrigin = "<gcp-project-id>/<url-map-name>"` in the deployment target config — exactly two slash-separated parts.
  2. Find the URL map name with `gcloud compute url-maps list` and use its short name, not the full resource path.
  3. If you don't use Google Cloud CDN, remove the `googleCloudCDNOrigin` setting or set `invalidateCDN = false`.

Example fix

# before (hugo.toml)
[[deployment.targets]]
googleCloudCDNOrigin = "projects/my-proj/global/urlMaps/my-map"
# after
[[deployment.targets]]
googleCloudCDNOrigin = "my-proj/my-map"
Defensive patterns

Strategy: validation

Validate before calling

func validOrigin(o string) bool {
    parts := strings.Split(o, "/")
    return len(parts) == 2 && parts[0] != "" && parts[1] != ""
}

Prevention

When it happens

Trigger: Running `hugo deploy` against a target whose `googleCloudCDNOrigin` config value does not contain exactly one `/` — e.g. just the project (`my-project`), an extra segment (`my-project/region/my-urlmap`), or an empty/trailing-slash value.

Common situations: Typos in `[deployment.targets]` config, pasting a full resource path (`projects/p/global/urlMaps/m`) instead of the short `<project>/<origin>` form, or confusing this field with the AWS `cloudFrontDistributionID` format.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/7bf481753ade4b08.json. Report an issue: GitHub ↗.