Terraform Plugin Framework - Float64 Type Validation Error

I’m working on a Terraform provider, where I have a resource which contains Float64 attributes.

Within the Schema I’ve specified this attribute;

"latitude": schema.Float64Attribute{
	Description:         "Latitude of the resource location",
	MarkdownDescription: "Latitude of the resource location",
	Optional:            true,
},

Everything compiles and runs, but the validation fails, when I try to set a value, which is not a “whole” number or a float ending with “.5” So these numbers work (123, 123.5), but all other numbers like (123.1, 123.2, etc.) fail.

The error I get is:

Float64 Type Validation Error: Value %!s(*big.Float=123.6) cannot be represented as a 64-bit floating point.

Since I’m new to the plugin framework, I’m not sure if I’m missing something or that this might be a bug within the framework. These are the (hashicorp) modules as shown in go.mod.

	github.com/hashicorp/terraform-plugin-framework v1.0.1
	github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect
	github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
	github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
	github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
	github.com/hashicorp/go-hclog v1.4.0 // indirect
	github.com/hashicorp/go-plugin v1.4.8 // indirect
	github.com/hashicorp/go-uuid v1.0.3 // indirect
	github.com/hashicorp/yamux v0.1.1 // indirect

Hi @rob.maas :wave: Thank you for raising this topic. It doesn’t appear you are doing anything wrong here and I have verified that this is indeed a bug in terraform-plugin-framework’s validation handling for Float64 types. Could you raise a bug report so we can get this fixed up?

Thanks so much.

Until this is fixed, you can fallback to the Number type/attribute, which does not have the same validation (since its ultimately applying the same logic as Terraform core’s type system). It does have the slight downside of being a big package - math/big - Go Packages instead of the more convenient float64 Go type, but there is the (*big.Float).Float64() method which can be used to convert it to float64.

1 Like

Sorry, I completely missed that 1.1.0 was released already.

Unfortunately I tried using the float option with release 1.1.1, but it keeps coming with the same error.

Output of terraform plan.

Error: Value %!s(*big.Float=51.12) cannot be represented as a 64-bit floating point.

go.mod

require (
	github.com/hashicorp/terraform-plugin-framework v1.1.1
	github.com/on2itsecurity/go-auxo v1.0.1
)

require (
	github.com/golang/protobuf v1.5.2 // indirect
	github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect
	github.com/hashicorp/terraform-plugin-log v0.7.0 // indirect
	github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
	github.com/hashicorp/terraform-svchost v0.1.0 // indirect
	github.com/kr/pretty v0.3.0 // indirect
	github.com/mattn/go-isatty v0.0.17 // indirect
	github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
	github.com/vmihailenco/tagparser v0.1.2 // indirect
	google.golang.org/protobuf v1.28.1 // indirect
)

I can see the changes within my local vendor folder, so that seems all ok.

Should I re-open the case or do you want me to create a new one @bflad ?

If you could open a new issue, that would be very appreciated. Thank you.

For any followers of this thread, we merged a fix to this bug here: types/basetypes: Fixed Float64Type value conversion to handle stringified numbers by austinvalle · Pull Request #648 · hashicorp/terraform-plugin-framework · GitHub

We’ll look to release that with the upcoming v1.2.0 Milestone · GitHub

Thanks! :+1:

2 Likes