Repository: honeycombio/terraform-provider-honeycombio (language: python)

Issue:
Floating point rounding issues in 0.15.x
**Versions**
0.15.0, 0.15.1

**Steps to reproduce**

1. Add a new `honeycombio_trigger`. I used
    ```tf
    terraform {
      required_providers {
        honeycombio = {
          source  = "honeycombio/honeycombio"
          version = "= 0.15.0"
        }
      }
    }
    
    provider "honeycombio" {
      api_key = "testing"
    }
    
    resource "honeycombio_trigger" "fp_test" {
      name = "testing"
    
      dataset  = "testing"
      query_id = "testing"
    
      threshold {
        op    = ">"
        value = 1 - 0.99
      }
    }
    ```
2. Run `terraform plan`
3. Set provider version to `0.14.0`
4. Run `terraform init -upgrade && terraform plan`

With 0.15.0 (and 0.15.1), I get the error

```tf
│ Error: Provider produced invalid plan
│
│ Provider "registry.terraform.io/honeycombio/honeycombio" planned an invalid value for
│ honeycombio_trigger.fp_test.threshold[0].value: planned value cty.NumberFloatVal(0.01) does not match config value
│ cty.MustParseNumberVal("0.010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003").
│
```

But with 0.14.0, it generates the expected plan

```tf
  # honeycombio_trigger.fp_test will be created
  + resource "honeycombio_trigger" "fp_test" {
      + alert_type = "on_change"
      + dataset    = "testing"
      + frequency  = (known after apply)
      + id         = (known after apply)
      + name       = "testing"
      + query_id   = "testing"

      + threshold {
          + op    = ">"
          + value = 0.01
        }
    }
```

**Additional context**

In short, the Honeycomb provider is no longer handling floating point rounding the way it used to. Terraform itself produces floating point inaccuracies for `1 - x`, where `0.783 <= x < 1.0`, at least on my architecture:
```sh
> 1 - 0.782
0.218
> 1 - 0.783
0.21700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
> 1 - 0.995
0.004999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999964
```
Previously, the provider handled this gracefully, correctly rounding these decimals - but no longer.

This is a pattern we use heavily because we keep a central directory of services, SLOs, etc, and the triggers are generated based on them - so if we have an SLO of `0.995` defined on a service, we generate a failure trigger with threshold `1 - 0.995`.



Discussion / hints:
@jharley this leaves is stuck between a rock and a hard place, since 0.14.0 has the issue with recipients, and this 0.15.0 has this issue. Before we try to make significant workarounds, or look into the issue ourselves, do you have an idea of when this can be triaged and worked on?

Thought about looking at this again, but right now the provider throws this:

```
Stack trace from the terraform-provider-honeycombio_v0.15.1 plugin:

panic: runtime error: index out of range [-1]

goroutine 4812 [running]:
github.com/honeycombio/terraform-provider-honeycombio/internal/provider.(*triggerResource).Read(0x14000814000, {0x100e18580, 0x1400078b5c0}, {{{{0x100e1d0c8, 0x1400080ef90}, {0x100d1ff20, 0x14000c65cb0}}, {0x100e1e868, 0x140003c0820}}, 0x14000814050, ...}, ...)
	github.com/honeycombio/terraform-provider-honeycombio/internal/provider/trigger_resource.go:397 +0x764
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0x140001d5e40, {0x100e18580, 0x1400078b5c0}, 0x1400078b6e0, 0x1400051b3c0)
	github.com/hashicorp/terraform-plugin-framework@v1.2.0/internal/fwserver/server_readresource.go:97 +0x4a4
github.com/hashicorp/terraform-plugin-framework/internal/proto5server.(*Server).ReadResource(0x140001d5e40, {0x100e18580?, 0x1400078b410?}, 0x14000b102c0)
	github.com/hashicorp/terraform-plugin-framework@v1.2.0/internal/proto5server/server_readresource.go:53 +0x1a4
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ReadResource({0x14000349ad0, 0x14000349b30, {0x140001b1b80, 0x2, 0x2}, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
	github.com/hashicorp/terraform-plugin-mux@v0.10.0/tf5muxserver/mux_server_ReadResource.go:26 +0xdc
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x140002c74a0, {0x100e18580?, 0x1400078a240?}, 0x14000624d20)
	github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/tf5server/server.go:748 +0x3e8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x100ddfa00?, 0x140002c74a0}, {0x100e18580, 0x1400078a240}, 0x140003d20e0, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.15.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:383 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140002c21e0, {0x100e1d4e0, 0x140004c2680}, 0x140003899e0, 0x140004b45d0, 0x101318970, 0x0)
	google.golang.org/grpc@v1.54.0/server.go:1345 +0xc64
google.golang.org/grpc.(*Server).handleStream(0x140002c21e0, {0x100e1d4e0, 0x140004c2680}, 0x140003899e0, 0x0)
	google.golang.org/grpc@v1.54.0/server.go:1722 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	google.golang.org/grpc@v1.54.0/server.go:966 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.54.0/server.go:964 +0x290

Error: The terraform-provider-honeycombio_v0.15.1 plugin crashed!
```
@purajit I have just confirmed I can reproduce this bug, thanks for reporting it.

This appears to be a difference in how the new Terraform Plugin Framework parses things (0.15 of the provider is a migration of the `honeycombio_trigger` resource from the Plugin SDKv2 to the new Plugin Framework). I'll see what we can do about a quick fix here 👍🏻 

As for the panic, that is another bug that we are aware of but I've yet to be given a reproducible case to trigger it. If you have such a thing I'd very much appreciate you sharing it so we can get that one squashed as well!

Fix patch:
diff --git a/go.mod b/go.mod
index 47a59ece..76c71517 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.19
 
 require (
 	github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
-	github.com/hashicorp/terraform-plugin-framework v1.3.3
+	github.com/hashicorp/terraform-plugin-framework v1.3.4
 	github.com/hashicorp/terraform-plugin-go v0.18.0
 	github.com/hashicorp/terraform-plugin-mux v0.11.2
 	github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
diff --git a/go.sum b/go.sum
index 100a87ef..3a0fee35 100644
--- a/go.sum
+++ b/go.sum
@@ -60,8 +60,8 @@ github.com/hashicorp/terraform-exec v0.18.1 h1:LAbfDvNQU1l0NOQlTuudjczVhHj061fNX
 github.com/hashicorp/terraform-exec v0.18.1/go.mod h1:58wg4IeuAJ6LVsLUeD2DWZZoc/bYi6dzhLHzxM41980=
 github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA=
 github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o=
-github.com/hashicorp/terraform-plugin-framework v1.3.3 h1:D18BlA8gdV4+W8WKhUqxudiYomPZHv94FFzyoSCKC8Q=
-github.com/hashicorp/terraform-plugin-framework v1.3.3/go.mod h1:2gGDpWiTI0irr9NSTLFAKlTi6KwGti3AoU19rFqU30o=
+github.com/hashicorp/terraform-plugin-framework v1.3.4 h1:dOTLsALgmQu+PawAvhfGQ04H0MeIz3EZmBw7OFvj7qs=
+github.com/hashicorp/terraform-plugin-framework v1.3.4/go.mod h1:2gGDpWiTI0irr9NSTLFAKlTi6KwGti3AoU19rFqU30o=
 github.com/hashicorp/terraform-plugin-framework-validators v0.10.0 h1:4L0tmy/8esP6OcvocVymw52lY0HyQ5OxB7VNl7k4bS0=
 github.com/hashicorp/terraform-plugin-framework-validators v0.10.0/go.mod h1:qdQJCdimB9JeX2YwOpItEu+IrfoJjWQ5PhLpAOMDQAE=
 github.com/hashicorp/terraform-plugin-go v0.18.0 h1:IwTkOS9cOW1ehLd/rG0y+u/TGLK9y6fGoBjXVUquzpE=


Test patch:
diff --git a/internal/provider/trigger_resource_test.go b/internal/provider/trigger_resource_test.go
index da8ea0c2..9a4e0931 100644
--- a/internal/provider/trigger_resource_test.go
+++ b/internal/provider/trigger_resource_test.go
@@ -405,6 +405,49 @@ resource "honeycombio_trigger" "test" {
 	})
 }
 
+func TestAcc_TriggerResourceThresholdFloatingPointBug(t *testing.T) {
+	// reported as https://github.com/honeycombio/terraform-provider-honeycombio/issues/335
+	dataset := testAccDataset()
+
+	resource.Test(t, resource.TestCase{
+		PreCheck:                 testAccPreCheck(t),
+		ProtoV5ProviderFactories: testAccProtoV5MuxServerFactory,
+		Steps: []resource.TestStep{
+			{
+				Config: fmt.Sprintf(`
+data "honeycombio_query_specification" "test" {
+  calculation {
+    op     = "COUNT"
+  }
+
+  time_range = 1200
+}
+
+resource "honeycombio_query" "test" {
+  dataset    = "%[1]s"
+  query_json = data.honeycombio_query_specification.test.json
+}
+
+resource "honeycombio_trigger" "test" {
+  name = "floating point test"
+
+  dataset  = "%[1]s"
+  query_id = honeycombio_query.test.id
+
+  threshold {
+    op    = ">"
+    value = 1 - 0.99
+  }
+}
+`, dataset),
+				Check: resource.ComposeTestCheckFunc(
+					testAccEnsureTriggerExists(t, "honeycombio_trigger.test"),
+				),
+			},
+		},
+	})
+}
+
 func testAccConfigBasicTriggerTest(dataset, pdseverity string) string {
 	return fmt.Sprintf(`
 data "honeycombio_query_specification" "test" {