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

Issue:
d/query_specification: failing validation on "auto" granularity = 0
Reported via Pollinators:

> with the [0.24.0] release we faced the following issue:
Error: invalid granularity
│ 
│   with data.honeycombio_query_specification.xxxx,
│   on xxxx.tf line 132, in data "xxxx" "xxxx":
│  132:   granularity = 0
│ 
│ granularity can not be less than time_range/1000

> For one this does not affect queries using the JSON based definition (which is kinda expected - I'd guess)
> Also: iirc granularity = 0  used to mean auto hence the value should be fine; For the time being we removed all granularity = 0 statements, relying on the implicit default, but I'm wondering if this is intentional.


Discussion / hints:

Fix patch:
diff --git a/client/v2/client.go b/client/v2/client.go
index 120afffc..15772721 100644
--- a/client/v2/client.go
+++ b/client/v2/client.go
@@ -208,7 +208,7 @@ func (c *Client) retryHTTPCheck(
 	case http.StatusTooManyRequests:
 		// TODO: use new retry header timestamps to determine when to retry
 		return true, nil
-	case http.StatusBadGateway, http.StatusGatewayTimeout:
+	case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusInternalServerError:
 		return true, nil
 	default:
 		return false, nil
diff --git a/internal/provider/query_specification_data_source.go b/internal/provider/query_specification_data_source.go
index 46eddb0a..14811427 100644
--- a/internal/provider/query_specification_data_source.go
+++ b/internal/provider/query_specification_data_source.go
@@ -403,7 +403,7 @@ func (d *querySpecDataSource) Read(ctx context.Context, req datasource.ReadReque
 				"granularity can not be greater than time_range/10",
 			)
 		}
-		if *querySpec.Granularity < (*querySpec.TimeRange / 1000) {
+		if *querySpec.Granularity != 0 && *querySpec.Granularity < (*querySpec.TimeRange/1000) {
 			resp.Diagnostics.AddAttributeError(
 				path.Root("granularity"),
 				"invalid granularity",


Test patch:
diff --git a/internal/provider/query_specification_data_source_test.go b/internal/provider/query_specification_data_source_test.go
index 2779e095..91f21bb7 100644
--- a/internal/provider/query_specification_data_source_test.go
+++ b/internal/provider/query_specification_data_source_test.go
@@ -399,7 +399,8 @@ func TestAcc_QuerySpecificationDataSource_zerovalue(t *testing.T) {
       "value": 0
     }
   ],
-  "time_range": 7200
+  "time_range": 7200,
+  "granularity": 0
 }`)
 	require.NoError(t, err)
 
@@ -419,6 +420,8 @@ data "honeycombio_query_specification" "test" {
     op     = ">"
     value  = 0
   }
+
+  granularity = 0
 }
 
 output "query_json" {