hashicorp / hashicorp/terraform-plugin-framework
Provider Attribute Default to properly support muxing with SDKv2 provider
- Dominant language
- Go
- Stars
- 384
- Forks
- 107
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
This "request" is related to https://github.com/hashicorp/terraform-plugin-mux as well, but I figured it makes more sense here, because the framework doesn't yet provide a proper solution for this - but feel free to move it to the appropriate repository.
I'm currently prototyping a migration from a SDKv2 provider to the framework and implemented a muxing provider server with:
1. upgraded SDKv2 provider (to protocol v6)
2. framework provider
The SDKv2 provider has a provider attribute schema with defaults, e.g.:
```go
"token": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("GITLAB_TOKEN", nil),
},
"cacert_file": {
Type: schema.TypeString,
Optional: true,
Default: "",
},
"insecure": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
```
Accordingly the framework provider must have the same attribute schema, e.g.:
```go
"token": {
Type: types.StringType,
Optional: true,
},
"cacert_file": {
Type: types.StringType,
Optional: true,
},
"insecure": {
Type: types.BoolType,
Optional: true,
},
```
AFAIK The framework doesn't yet support a mechanism to declaratively set a default value - which "functionally" isn't a problem, because I can set them in the `Configure()` method.
However, it's a problem with muxing, because the `tf6muxserver` actually checks if the `PreparedConfig` RPC responses match from all servers:
https://github.com/hashicorp/terraform-plugin-mux/blob/411419dcd18e833d58a543344d009dadb7594bb9/tf6muxserver/mux_server_ValidateProviderConfig.go#L58
The thing is that the `PreparedConfig` from the SDKv2 provider contains the evaluated defaults ...
A related problem to the inability to declare defaults in framework providers when using muxing, is that previously required attributes with a default now must be optional - which also requires a change in the SDKv2 provider to make muxing work.
One solution could be to remove the defaults from the SDKv2 provider schema and also evaluate them in the `configure` hook function - but I'd rather not do that.
Is this the only solution? Am I missing something? If that's really the only possible solution atm - is there a change to be expected to make this more ergonomic ?
Contributor guide
Assessment
This issue has not been assessed yet.