---
page_title: 'Plugin Development - Framework: Object Function Return'
description: >-
  Learn the object function return type in the provider development framework.
---

# Object Function Return

Object function return expects a single structure mapping explicit attribute names to type definitions from function logic. Set values in function logic with a Go structure type annotated with `tfsdk` field tags or the [framework map type](/terraform/plugin/framework/handling-data/types/map).

## Function Definition

Use the [`function.ObjectReturn` type](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/function#ObjectReturn) in the [function definition](/terraform/plugin/framework/functions/implementation#definition-method).

The `AttributeTypes` field must be defined, which represents a mapping of attribute names to [framework value types](/terraform/plugin/framework/handling-data/types). An attribute type may itself contain further collection or object types, if necessary.

In this example, a function definition includes an object return:

```go
func (f ExampleFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) {
    resp.Definition = function.Definition{
        // ... other Definition fields ...
        Return: function.ObjectReturn{
            AttributeTypes: map[string]attr.Type{
                "attr1": types.StringType,
                "attr2": types.Int64Type,
            },
            // ... potentially other ObjectReturn fields ...
        },
    }
}
```

### Custom Types

You may want to build your own data value and type implementations to allow your provider to combine validation and other behaviors into a reusable bundle. This helps avoid duplication and ensures consistency. These implementations use the `CustomType` field in the return type.

Refer to [Custom Types](/terraform/plugin/framework/handling-data/types/custom) for further details on creating provider-defined types and values.

### Documentation

Return documentation is expected in the top-level function documentation. Refer to [function documentation](/terraform/plugin/framework/functions/documentation) for information about the `Summary`, `Description`, and `MarkdownDescription` fields available.

## Setting Return Data

The [function implementation](/terraform/plugin/framework/functions/implementation) documentation covers the general methods for setting function return data in function logic.

When setting the value for this return:

* If `CustomType` is set, use its associated value type.
* Otherwise, use a Go structure type annotated with `tfsdk` field tags or [framework map type](/terraform/plugin/framework/handling-data/types/map).

In this example, a function defines a map of string return and sets its value:

```go
func (f ExampleFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) {
    resp.Definition = function.Definition{
        // ... other Definition fields ...
        Return: function.ObjectReturn{
            AttributeTypes: map[string]attr.Type{
                "attr1": types.StringType,
                "attr2": types.Int64Type,
            },
        },
    }
}

func (f ExampleFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
    // ... other logic ...

    // hardcoded structure type and value for example brevity
    result := struct{
        Attr1 string `tfsdk:"attr1"`
        Attr2 int64  `tfsdk:"attr2"`
    }{
        Attr1: "value1",
        Attr2: 123,
    }

    resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, &result))
}
```
