grafana/k6 · error

stack ID not configured

Error message

stack ID not configured

What it means

errMissingStackID is the second leg of checkCloudLoginFor: a token is configured but `conf.StackID` is unset or zero, so k6 has no stack to address cloud API calls against and refuses before any request. It is wrapped under the command's auth prefix together with the login advisory.

Source

Thrown at internal/cmd/cloud.go:40

	"go.k6.io/k6/v2/internal/build"
	cloudapiv6 "go.k6.io/k6/v2/internal/cloudapi/v6"
	"go.k6.io/k6/v2/internal/ui/pb"
	"go.k6.io/k6/v2/lib"

	"github.com/fatih/color"
	"github.com/spf13/cobra"
	"github.com/spf13/pflag"
)

const cloudRunAuthPrefix = "Running cloud tests requires auth settings"

var (
	errCloudAuth = errors.New( //nolint:staticcheck // user-facing error message, capitalization is intentional
		"Run `k6 cloud login` to authenticate, or check the docs for other options at" +
			" https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication",
	)
	errMissingToken   = errors.New("access token not configured")
	errMissingStackID = errors.New("stack ID not configured")

	// errNoProjectConfigured is returned by cloud sub-commands that require a
	// concrete project to operate on when none can be resolved from the flags,
	// the environment, or the logged-in configuration.
	errNoProjectConfigured = errors.New(
		"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project",
	)
)

// checkCloudLogin verifies that both a token and a stack are configured.
// Together they represent a complete Grafana Cloud login.
func checkCloudLogin(conf cloudapi.Config) error {
	return checkCloudLoginFor(conf, cloudRunAuthPrefix)
}

func checkCloudLoginFor(conf cloudapi.Config, prefix string) error {
	if !conf.Token.Valid || conf.Token.String == "" {
		return fmt.Errorf("%s: %w.\n%w", prefix, errMissingToken, errCloudAuth)

View on GitHub (pinned to 94169daab2)

Solutions

  1. Run `k6 cloud login -t <token> --stack <stack-url-or-slug>` — the auth response resolves and stores the numeric stack ID
  2. In CI, additionally export K6_CLOUD_STACK_ID with the numeric stack ID shown in Grafana Cloud
  3. Inspect stored state with `k6 cloud login -s`; if stack-id shows <not set>, redo the login
  4. If you hand-maintain the config JSON, ensure both 'token' and 'stackID' keys exist under collectors.cloud

Example fix

# before
export K6_CLOUD_TOKEN=glc_ey...
k6 cloud run script.js   # -> stack ID not configured

# after
export K6_CLOUD_TOKEN=glc_ey...
export K6_CLOUD_STACK_ID=123456
k6 cloud run script.js
Defensive patterns

Strategy: validation

Validate before calling

: "${K6_CLOUD_TOKEN:?K6_CLOUD_TOKEN required}"
: "${K6_CLOUD_STACK_ID:?K6_CLOUD_STACK_ID required (numeric stack ID from Grafana Cloud)}"
case "$K6_CLOUD_STACK_ID" in ''|*[!0-9]*) echo 'K6_CLOUD_STACK_ID must be numeric'; exit 1;; esac

Prevention

When it happens

Trigger: Cloud commands when K6_CLOUD_TOKEN is set but K6_CLOUD_STACK_ID is not; or the config file contains a token but no stack-id — common when migrating from the legacy flow where only a token was needed, or when only the token key was hand-edited into the JSON config.

Common situations: CI pipelines built for older k6 versions (token-only auth) run against newer k6 requiring token+stack; users copying a token into config manually; logins made against a stack whose ID could not be resolved.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18). Data as JSON: /api/errors/e4ddac92bdf02d5f. Report an issue: GitHub.