hashicorp / hashicorp/terraform-plugin-framework

Default values in provider functions

Open
#1,012 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
384
Forks
107
Avg merge
3m
Merged PRs (30d)
1

Description

### Module version

```
github.com/hashicorp/terraform-plugin-framework v1.9.0
```

### Use-cases

Omit arguments in provider functions when the default is already the correct value.

e.g. My [provider function](https://registry.terraform.io/providers/germanbrew/dotenv/latest/docs/functions/get_by_key#example-usage) has a filename argument that often is the same value: `.env`

### Attempted Solutions

Setting defaults to provider functions in the Plugin Framework does not work or I was not able to.

### Proposal

Provide a additional `Default` key to the function definition to specify a default value to a parameter:

```go
func (r ExampleFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Example function",
MarkdownDescription: "Foo bar",
Parameters: []function.Parameter{
function.StringParameter{
Name: "filename",
MarkdownDescription: "Path to the dotenv file",
// Add this
Default: ".env",
},
},
Return: function.StringReturn{},
}
}
```

### References

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.