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

Issue:
Setting filter_combination to AND leads to noisy plan
**Versions**
```hcl
    honeycombio = {
      source  = "honeycombio/honeycombio"
      version = "~> 0.3.0"
    }
```

**Steps to reproduce**

1. Run `terraform apply` to create a trigger with `filter_combination` set to `AND` in `honeycombio_query_specification`.
2. Run `terraform plan`.

Expected result: plan is empty
Actual results: plan is not empty since it tries to add filter combination with `AND` again:

```hcl
  # module.test.honeycombio_query.this[0] must be replaced
-/+ resource "honeycombio_query" "this" {
      ~ id         = "JrEwdX44JCu" -> (known after apply)
      ~ query_json = jsonencode(
          ~ {
              + filter_combination = "AND"
                # (3 unchanged elements hidden)
            } # forces replacement
        )
        # (1 unchanged attribute hidden)
    }

  # module.test.honeycombio_trigger.this["#alex-test"] will be updated in-place
  ~ resource "honeycombio_trigger" "this" {
        id          = "prn53msd1kA"
        name        = "Alex test (#alex-test)"
      ~ query_id    = "JrEwdX44JCu" -> (known after apply)
        # (4 unchanged attributes hidden)


        # (2 unchanged blocks hidden)
    }
```

**Additional context**

Looks like API returns null for filter combination if it set to "default" `AND`.
We can workaround it with something like
```hcl
filter_combination = var.filter_combination == "AND" ? null : var.filter_combination
```
but it would be nice to make it more user friendly.


Discussion / hints:

Fix patch:
diff --git a/honeycombio/data_source_query_specification.go b/honeycombio/data_source_query_specification.go
index 40c0344e..3b44cee8 100644
--- a/honeycombio/data_source_query_specification.go
+++ b/honeycombio/data_source_query_specification.go
@@ -111,9 +111,9 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
 				},
 			},
 			"filter_combination": {
-				Type:     schema.TypeString,
-				Optional: true,
-				// Note: API assumes 'AND' if not provided
+				Type:         schema.TypeString,
+				Optional:     true,
+				Default:      "AND",
 				ValidateFunc: validation.StringInSlice([]string{"AND", "OR"}, false),
 			},
 			"breakdowns": {
@@ -211,11 +211,20 @@ func dataSourceHoneycombioQuerySpecRead(ctx context.Context, d *schema.ResourceD
 		}
 	}
 
+	// The API doesn't return filter_combination if it is 'AND' (the default)
+	var filterCombination honeycombio.FilterCombination
+	filterString := d.Get("filter_combination").(string)
+	if filterString != "" && filterString != "AND" {
+		// doing it this way to support possible different filter types in future
+		// and having one less place to update them
+		filterCombination = honeycombio.FilterCombination(filterString)
+	}
+
 	query := &honeycombio.QuerySpec{
 		Calculations:      calculations,
 		Filters:           filters,
 		Havings:           havings,
-		FilterCombination: honeycombio.FilterCombination(d.Get("filter_combination").(string)),
+		FilterCombination: filterCombination,
 		Breakdowns:        extractBreakdowns(d),
 		Orders:            extractOrders(d),
 		Limit:             extractOptionalInt(d, "limit"),


Test patch:
diff --git a/honeycombio/data_source_query_specification_test.go b/honeycombio/data_source_query_specification_test.go
index a82853a0..68bb3a32 100644
--- a/honeycombio/data_source_query_specification_test.go
+++ b/honeycombio/data_source_query_specification_test.go
@@ -54,6 +54,8 @@ data "honeycombio_query_specification" "test" {
         value  = "ThatSpecialTenant"
     }
 
+    filter_combination = "OR"
+
     breakdowns = ["column_1"]
 
     order {
@@ -115,6 +117,7 @@ const expectedJSON string = `{
       "value": "ThatSpecialTenant"
     }
   ],
+  "filter_combination": "OR",
   "breakdowns": [
     "column_1"
   ],
diff --git a/honeycombio/resource_board_test.go b/honeycombio/resource_board_test.go
index a1ee91e9..255db7d7 100644
--- a/honeycombio/resource_board_test.go
+++ b/honeycombio/resource_board_test.go
@@ -44,6 +44,8 @@ data "honeycombio_query_specification" "test" {
     column = "duration_ms"
   }
 
+  filter_combination = "AND"
+
   filter {
     column = "duration_ms"
     op     = ">"
diff --git a/honeycombio/resource_trigger_test.go b/honeycombio/resource_trigger_test.go
index 44906a89..339f0821 100644
--- a/honeycombio/resource_trigger_test.go
+++ b/honeycombio/resource_trigger_test.go
@@ -211,10 +211,24 @@ resource "honeycombio_trigger" "test" {
 func testAccTriggerConfigWithCount(dataset string) string {
 	return fmt.Sprintf(`
 data "honeycombio_query_specification" "test" {
+  time_range = 1200
+
   calculation {
     op     = "COUNT"
   }
-  time_range = 1200
+
+  filter_combination = "AND"
+
+  filter {
+    column = "trace.parent_id"
+    op     = "does-not-exist"
+  }
+
+  filter {
+    column = "app.tenant"
+    op     = "="
+    value  = "ThatSpecialTenant"
+  }
 }
 
 resource "honeycombio_query" "test" {