hashicorp / hashicorp/terraform-plugin-docs
Question: Is showing a Required field as Optional when setting DefaultFunc the best approach?
- Dominant language
- Go
- Stars
- 263
- Forks
- 84
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 2
Description
Hello 👋🏻
I'm opening this more for a general discussion regarding the use of `DefaultFunc` with a required field.
I've noticed that when adding `DefaultFunc` to an otherwise required field it's rendered in the documentation as 'optional'.
Now this make sense because if the value isn't provided by the user in their configuration, then we'll use `schema.EnvDefaultFunc` to get a value (otherwise we return an empty string), but it's also a little bit confusing when you look at the code and see `Required: true` compared to the documentation saying it's 'optional'.
```go
"user": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("SOME_ENV_VAR", ""),
}
```
I'm not sure if it's better to still have this field be shown as 'required' in the documentation because ultimately if the user doesn't provide a value (not in config, nor in the environment var) then we'll end up setting an empty string which will (in our case definitely) cause errors. I'd personally still prefer to see this field under "Required" to be explicit that regardless of the use of `DefaultFunc` the user should pay special attention to it.
Thoughts?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.