Open mavogel opened 3 years ago
While not official, you can achieve this with a workaround in your own provider. Check out https://github.com/cloudflare/terraform-provider-cloudflare/blob/master/internal/provider/provider.go#L23-L48 for an example.
@jacobbednarz Any chance that you have similar workaround for providers based on terraform-plugin-framework?
nothing that exists today. it has been requested at https://github.com/hashicorp/terraform-plugin-framework/issues/625 though if you'd like to track it.
hi, let me put my 2 cents here. In PluginFramework it is possible using custom types.
Here is a naive implementation for String
Terraform core type (you will have to implement it for all types which are in use):
type stringDefault struct {
schema.StringAttribute
}
func (a stringDefault) GetDescription() string {
origDescription := a.StringAttribute.GetDescription()
if a.Default == nil {
return origDescription
}
resp := defaults.StringResponse{}
a.Default.DefaultString(context.TODO(), defaults.StringRequest{}, &resp)
origDescription = fmt.Sprintf(`%s Default: %s`, origDescription, resp.PlanValue)
return origDescription
}
and then use this wrapper in Schema
method of the resource:
func (s *bridgeVlan) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"string_attribute": stringDefault{
schema.StringAttribute{
Optional: true,
Computed: true,
Default: stringdefault.StaticString("default value"),
},
},
},
}
}
Current behavior
Given the schema entry:
the rendered output is
Desired behavior
I'd like to have
Defaults to abc
in the generation as well as follows:Versions
v0.4.0
v2.6.1