Custom provider: object attribute with floats. MustParseNumberVal

Hi,
I’m writing a provider, and one of th resources has the following schema:

...
"location": {
	Type: types.ObjectType{
		AttrTypes: map[string]attr.Type{
			"latitude":  types.Float64Type,
			"longitude": types.Float64Type,
			"altitude":  types.Float64Type,
			"source":    types.StringType,
		},
	},
	Required: true,
},
...

When I try to create a resource I get the following error during the plan phase:

Provider "..." planned an invalid value for..: planned value 
cty.ObjectVal(map[string]cty.Value{
"altitude":cty.NumberIntVal(0), 
"latitude":cty.NumberFloatVal(48.12029), 
"longitude":cty.NumberFloatVal(-1.63426),
"source":cty.StringVal("CONFIG")})
 does not match config value 
cty.ObjectVal(map[string]cty.Value{
"altitude":cty.NumberIntVal(0),
"latitude":cty.MustParseNumberVal("48.12029"), 
"longitude":cty.MustParseNumberVal("-1.63426"),
"source":cty.StringVal("CONFIG")}).

The data is stored in this struct:

type ... struct {
...
	Location         types.Object `tfsdk:"location"`
...
}

I’m not sure where I went wrong and I can’t find anything on internet.

Hi @guillaumejchauveau,

That looks like a bug somewhere, but I would need more information to try and determine exactly where. Can you verify you are using the latest versions of both the plugin framework and the Terraform CLI?

If both are up to date, I would submit an issue in terraform-plugin-framework repo with the steps to reproduce the error.

Thanks!

Looks like someone has already reported this here: Terraform plan/apply fails when setting a float field to a float value · Issue #216 · hashicorp/terraform-plugin-framework · GitHub

1 Like

I confirm that I’m using the latest version, I guess I’ll wait for a patch. Thanks !