I’m building a Terraform Provider. I’ve hit a case where a Custom RuleCondition 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
}
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.