I am attempting to migrate an existing provider from SDKv2 to Framework and the strictness of the Framework is causing some errors.
The schema contains a Map that the user can define, additionally the API can modify the collection due to internal rules.
schema.MapAttribute{
Computed: true,
Optional: true,
Description: "A list of properties",
ElementType: types.StringType,
The config can have n values but if it is missing specific values they will be added by, for example:
properties = {
"Property1" = "value1"
}
The return value from the API, will return:
properties = {
"Property1" = "value1"
"Property2" = "value2"
}
When this is mapped back to the state in the provider I get an error, Error: Provider produced inconsistent result after apply
, new element "Property2" has appeared.
If the user adds Property2
in to the config directly there are no errors, but this relies on the user knowing this or modifying due to the error. Additionally, it doesn’t feel like the Property2
default should be hard coded or forced via validation, tomorrow the defaults might change and the provider ends up chasing the API.
I also tried adding the attribute plan modifier for this specific case, but it still errors the same:
if req.PlanValue.IsUnknown() {
properties := make(map[string]attr.Value)
properties["Property2"] = types.StringValue("true")
req.PlanValue = types.MapValueMust(types.StringType, properties)
return
}
current := req.PlanValue.Elements()
if _, ok := current["Property2"]; !ok {
current["Property2"] = types.StringValue("true")
req.PlanValue = types.MapValueMust(types.StringType, current)
return
}
Also, if the user adds Property2
to the config the plan should be a no-op, but in this case the state won’t actually represent the state of the API, but is forced to represent the state of the config only.
Is there a solution to allow the config to be different that the state where the API determines it to be .