Schema attribute can be one, of two types

I’m building a Terraform Provider. I’ve hit a case where a Custom Rule Condition can be a String or it can be an Object. What would be the best way of handling this case? This is my first time for building a provider with terraform-plugin-framework

type CustomRuleResourceModel struct {
	ID          types.String           `tfsdk:"id"`
	Description types.String           `tfsdk:"description"`
	Type        types.String           `tfsdk:"type"`
	Conditions  []CustomConditionModel `tfsdk:"condition"`
	Priority    types.Int64            `tfsdk:"priority"`
}
type CustomConditionModel struct {
	Category types.String `tfsdk:"category"`
	Value    types.String `tfsdk:"value"` // This can now be a String, or Map
}

Hi @kderck :wave:

It seems as though your description of CustomConditionModel.Value aligns with dynamic types. There has been some discussion around the usage of dynamic types, for instance Terraform-plugin-framework map of different value types and Support Dynamic Type/Attributes/Parameters on GitHub.

Dynamic type support is being considered, but has not yet been implemented in the framework. Refer to https://discuss.hashicorp.com/t/terraform-plugin-framework-map-of-different-value-types/56421/7:

Your only option in this case might be to use a dynamic pseudo type from terraform-plugin-go along with muxing. There is currently an open issue on terraform-plugin-framework for Support Dynamic Type/Attributes that discusses this. But until such time that this is added to the framework it may be necessary to use terraform-plugin-go along with muxing.

Hi @bendbennett in the end I decided to change the structure be a String JSON Type.