pulumi/pulumi · error

sha1 requires an input argument

Error message

sha1 requires an input argument

What it means

The PCL sha1 builtin computes the SHA-1 hex digest of a string input. It throws this error when the function is invoked without exactly one argument in the args slice — typically zero arguments. The check runs before any type inspection.

Source

Thrown at pkg/pcl/runtime/builtinFunctions.go:987

			decodedBytes, err := base64.StdEncoding.DecodeString(data)
			if err != nil {
				return cty.NilVal, fmt.Errorf("invalid base64 data: %w", err)
			}
			return cty.StringVal(string(decodedBytes)), nil
		},
	})

	sha1Fn := function.New(&function.Spec{
		Params: []function.Parameter{
			{
				Name: "input",
				Type: cty.String,
			},
		},
		Type: function.StaticReturnType(cty.String),
		Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
			if len(args) != 1 {
				return cty.NilVal, errors.New("sha1 requires an input argument")
			}
			if args[0].Type() != cty.String {
				return cty.NilVal, errors.New("sha1 input argument must be a string")
			}
			h := sha1.Sum([]byte(args[0].AsString())) //nolint:gosec // we don't need a strong cryptographic primitive
			return cty.StringVal(hex.EncodeToString(h[:])), nil
		},
	})

	toJSONFn := function.New(&function.Spec{
		Params: []function.Parameter{
			{
				Name:             "value",
				Type:             cty.DynamicPseudoType,
				AllowMarked:      true,
				AllowNull:        true,
				AllowDynamicType: true,
			},

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Pass exactly one argument: sha1(value)
  2. If the input comes from a computed expression, ensure it is not dropped/empty before invocation

Example fix

// before
sha1()
// after
sha1("hello")
Defensive patterns

Strategy: validation

Validate before calling

// ensure exactly one argument at the call site: sha1(input)
if arg == nil { panic("sha1 requires one argument") }

Prevention

When it happens

Trigger: Calling sha1() with no arguments in a PCL program evaluated by the pcl runtime builtinFunctions registry.

Common situations: Accidentally deleting the argument while editing; a template interpolation that renders to zero arguments; copy-paste of the function name without filling in the input.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/9d7bef5950129911. Report an issue: GitHub.