hashicorp/terraform · error

provider has no function named %q

Error message

provider has no function named %q

What it means

Returned by `CallFunction` (provider.go:260) when the requested `FunctionName` is not a key in the `functions` map (`encode_tfvars`, `decode_tfvars`, `encode_expr`). The code comment notes this 'should not get here' if the caller respects the schema, because `GetProviderSchema().Functions` advertises exactly those three names.

Source

Thrown at internal/builtin/providers/terraform/provider.go:260

}

// CloseEphemeralResource implements providers.Interface.
func (p *Provider) CloseEphemeralResource(req providers.CloseEphemeralResourceRequest) providers.CloseEphemeralResourceResponse {
	var resp providers.CloseEphemeralResourceResponse
	resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("unsupported ephemeral resource type %q", req.TypeName))
	return resp
}

// CallFunction would call a function contributed by this provider, but this
// provider has no functions and so this function just panics.
func (p *Provider) CallFunction(req providers.CallFunctionRequest) providers.CallFunctionResponse {
	fn, ok := functions[req.FunctionName]
	if !ok {
		// Should not get here if the caller is behaving correctly, because
		// we don't declare any functions in our schema that we don't have
		// implementations for.
		return providers.CallFunctionResponse{
			Err: fmt.Errorf("provider has no function named %q", req.FunctionName),
		}
	}

	// NOTE: We assume that none of the arguments can be marked, because we're
	// expecting to be called from logic in Terraform Core that strips marks
	// before calling a provider-contributed function, and then reapplies them
	// afterwards.

	result, err := fn(req.Arguments)
	if err != nil {
		return providers.CallFunctionResponse{
			Err: err,
		}
	}
	return providers.CallFunctionResponse{
		Result: result,
	}
}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Use only `encode_tfvars`, `decode_tfvars`, or `encode_expr` with the built-in terraform provider.
  2. Introspect `GetProviderSchema().Functions` and only dispatch names present in that map.
  3. Upgrade or downgrade the caller/provider together so the expected function is advertised in the schema.

Example fix

// before
provider::terraform::encode_tfvar(local.obj)

// after
provider::terraform::encode_tfvars(local.obj)
Defensive patterns

Strategy: validation

Validate before calling

schema := provider.GetProviderSchema()
decl, ok := schema.Functions[req.FunctionName]
if !ok {
    return fmt.Errorf("function %q not advertised by terraform provider", req.FunctionName)
}
_ = decl

Type guard

func providerSupportsFunction(schema providers.GetProviderSchemaResponse, name string) bool {
    _, ok := schema.Functions[name]
    return ok
}

Prevention

When it happens

Trigger: An HCL expression `provider::terraform::<unknown>()`, or a Go caller of `providers.Interface.CallFunction` passing a `FunctionName` not in the three known functions.

Common situations: Typo in a function name; an experimental runtime dispatching functions without consulting `GetProviderSchema().Functions`; a version skew where a caller expects a function added in a newer Terraform than the provider build.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/49baf5af0ee52ab4. Report an issue: GitHub.