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

Issue:
r/honeycombio_board: removing "graph_settings" from query does not set all values to false
Due to what I believe is a limitation of the Plugin SDKv2, when removing `graph_settings` from a board `query` the values will not be all set to `false` but instead left as they were previously in state.

Bug discovered while investigating another bug related to `graph_settings` (see: #400).

Likely fix is to reimplement the `honeycombio_board` resource in the new Plugin Framework (as has been done for the trigger and burn alert resource).

**Steps to reproduce**

Add a query to a board with `graph_settings` set, apply it, then after creation remove the query's `graph_settings` block. When you run plan/apply again there will be no changes to apply but `terraform show` retains the old values.

**Additional context**

Suggested workaround is to either leave `graph_settings {}` in the `query` or simply leave one or more settings as `false`. e.g.

```hcl
resource "honeycombio_board" "myboard" {
[...]
  query {
    query_id = honeycombio_query.myquery.id
  
    graph_settings {
      utc_xaxis = false
    }
  }
}
```


Discussion / hints:

Fix patch:
diff --git a/client/board.go b/client/board.go
index cc2e45ed..c638c5cd 100644
--- a/client/board.go
+++ b/client/board.go
@@ -113,12 +113,12 @@ const (
 
 // BoardGraphSettings represents the display settings for an individual graph in a board.
 type BoardGraphSettings struct {
-	OmitMissingValues    bool `json:"omit_missing_values,omitempty"`
-	UseStackedGraphs     bool `json:"stacked_graphs,omitempty"`
-	UseLogScale          bool `json:"log_scale,omitempty"`
-	UseUTCXAxis          bool `json:"utc_xaxis,omitempty"`
-	HideMarkers          bool `json:"hide_markers,omitempty"`
-	PreferOverlaidCharts bool `json:"overlaid_charts,omitempty"`
+	OmitMissingValues    bool `json:"omit_missing_values"`
+	UseStackedGraphs     bool `json:"stacked_graphs"`
+	UseLogScale          bool `json:"log_scale"`
+	UseUTCXAxis          bool `json:"utc_xaxis"`
+	HideMarkers          bool `json:"hide_markers"`
+	PreferOverlaidCharts bool `json:"overlaid_charts"`
 }
 
 // BoardQueryStyles returns an exhaustive list of board query styles.
diff --git a/honeycombio/resource_board.go b/honeycombio/resource_board.go
index 940bcf27..c78b1250 100644
--- a/honeycombio/resource_board.go
+++ b/honeycombio/resource_board.go
@@ -78,7 +78,6 @@ func newBoard() *schema.Resource {
 						},
 						"graph_settings": {
 							Type:     schema.TypeList,
-							MinItems: 1,
 							MaxItems: 1,
 							Computed: true,
 							Optional: true,
@@ -88,37 +87,37 @@ See [Graph Settings](https://docs.honeycomb.io/working-with-your-data/graph-sett
 								Schema: map[string]*schema.Schema{
 									"log_scale": {
 										Type:        schema.TypeBool,
-										Computed:    true,
+										Default:     false,
 										Optional:    true,
 										Description: "Set the graph's Y axis to Log scale.",
 									},
 									"omit_missing_values": {
 										Type:        schema.TypeBool,
-										Computed:    true,
+										Default:     false,
 										Optional:    true,
 										Description: "Enable interpolatation between datapoints when the interveneing time buckets have no matching events.",
 									},
 									"hide_markers": {
 										Type:        schema.TypeBool,
-										Computed:    true,
+										Default:     false,
 										Optional:    true,
 										Description: "Disable the overlay of Markers on the graph.",
 									},
 									"stacked_graphs": {
 										Type:        schema.TypeBool,
-										Computed:    true,
+										Default:     false,
 										Optional:    true,
 										Description: "Enable the display of groups as stacked colored area under their line graphs.",
 									},
 									"utc_xaxis": {
 										Type:        schema.TypeBool,
-										Computed:    true,
+										Default:     false,
 										Optional:    true,
 										Description: "Set the graph's X axis to UTC.",
 									},
 									"overlaid_charts": {
 										Type:        schema.TypeBool,
-										Computed:    true,
+										Default:     false,
 										Optional:    true,
 										Description: "Allow charts to be overlaid when using supported Visualize operators.",
 									},


Test patch:
diff --git a/honeycombio/resource_board_test.go b/honeycombio/resource_board_test.go
index 2f0cf436..8608b25d 100644
--- a/honeycombio/resource_board_test.go
+++ b/honeycombio/resource_board_test.go
@@ -31,6 +31,7 @@ func TestAccHoneycombioBoard_basic(t *testing.T) {
 					resource.TestCheckResourceAttrPair("honeycombio_board.test", "query.0.query_annotation_id", "honeycombio_query_annotation.test.0", "id"),
 					resource.TestCheckResourceAttr("honeycombio_board.test", "query.1.caption", "test query 1"),
 					resource.TestCheckResourceAttr("honeycombio_board.test", "query.1.dataset", dataset),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.1.graph_settings.0.utc_xaxis", "false"),
 					resource.TestCheckResourceAttrPair("honeycombio_board.test", "query.1.query_id", "honeycombio_query.test.1", "id"),
 					resource.TestCheckResourceAttrPair("honeycombio_board.test", "query.1.query_annotation_id", "honeycombio_query_annotation.test.1", "id"),
 				),
@@ -42,10 +43,43 @@ func TestAccHoneycombioBoard_basic(t *testing.T) {
 			},
 		},
 	})
+}
+
+func TestAccHoneycombioBoard_updateGraphSettings(t *testing.T) {
+	dataset := testAccDataset()
+
 	resource.Test(t, resource.TestCase{
 		PreCheck:          testAccPreCheck(t),
 		ProviderFactories: testAccProviderFactories,
 		Steps: []resource.TestStep{
+			// setup a board with a single query with no graph settings
+			{
+				Config: fmt.Sprintf(`
+data "honeycombio_query_specification" "test" {
+  calculation {
+    op = "COUNT"
+  }
+}
+
+resource "honeycombio_query" "test" {
+  dataset    = "%s"
+  query_json = data.honeycombio_query_specification.test.json
+}
+
+resource "honeycombio_board" "test" {
+  name          = "simple board"
+
+  query {
+    query_id = honeycombio_query.test.id
+  }
+}`, dataset),
+				Check: resource.ComposeTestCheckFunc(
+					testAccCheckBoardExists(t, "honeycombio_board.test"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.log_scale", "false"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.utc_xaxis", "false"),
+				),
+			},
+			// now add a few graph settings to our query
 			{
 				Config: fmt.Sprintf(`
 data "honeycombio_query_specification" "test" {
@@ -61,24 +95,88 @@ resource "honeycombio_query" "test" {
 
 resource "honeycombio_board" "test" {
   name          = "simple board"
-  column_layout = "single"
 
   query {
     query_id = honeycombio_query.test.id
 
     graph_settings {
+      utc_xaxis = false
       log_scale = true
     }
   }
-}
-`, dataset),
+}`, dataset),
 				Check: resource.ComposeTestCheckFunc(
 					testAccCheckBoardExists(t, "honeycombio_board.test"),
 					resource.TestCheckResourceAttr("honeycombio_board.test", "name", "simple board"),
-					resource.TestCheckResourceAttr("honeycombio_board.test", "style", "visual"),
-					resource.TestCheckResourceAttr("honeycombio_board.test", "column_layout", "single"),
 					resource.TestCheckResourceAttr("honeycombio_board.test", "query.#", "1"),
 					resource.TestCheckResourceAttrPair("honeycombio_board.test", "query.0.query_id", "honeycombio_query.test", "id"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.log_scale", "true"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.utc_xaxis", "false"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.overlaid_charts", "false"),
+				),
+			},
+			// do a little shuffle of the settings and make sure we're all still updating
+			{
+				Config: fmt.Sprintf(`
+data "honeycombio_query_specification" "test" {
+  calculation {
+    op = "COUNT"
+  }
+}
+
+resource "honeycombio_query" "test" {
+  dataset    = "%s"
+  query_json = data.honeycombio_query_specification.test.json
+}
+
+resource "honeycombio_board" "test" {
+  name          = "simple board"
+
+  query {
+    query_id = honeycombio_query.test.id
+
+    graph_settings {
+      utc_xaxis = true
+    }
+  }
+}`, dataset),
+				Check: resource.ComposeTestCheckFunc(
+					testAccCheckBoardExists(t, "honeycombio_board.test"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.log_scale", "false"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.utc_xaxis", "true"),
+				),
+			},
+			// finally remove the graph settings and an ensure we're back to the defaults
+			{
+				// skipped due to bug: https://github.com/honeycombio/terraform-provider-honeycombio/issues/399
+				SkipFunc: func() (bool, error) { return true, nil },
+				Config: fmt.Sprintf(`
+data "honeycombio_query_specification" "test" {
+  calculation {
+    op = "COUNT"
+  }
+}
+
+resource "honeycombio_query" "test" {
+  dataset    = "%s"
+  query_json = data.honeycombio_query_specification.test.json
+}
+
+resource "honeycombio_board" "test" {
+  name          = "simple board"
+
+  query {
+    query_id = honeycombio_query.test.id
+
+    // below would have the test pass and is a workaround for the bug
+    // graph_settings {}
+  }
+}`, dataset),
+				Check: resource.ComposeTestCheckFunc(
+					testAccCheckBoardExists(t, "honeycombio_board.test"),
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.log_scale", "false"),
+					// this check currently fails due to the bug
+					resource.TestCheckResourceAttr("honeycombio_board.test", "query.0.graph_settings.0.utc_xaxis", "false"),
 				),
 			},
 		},
@@ -107,14 +205,14 @@ data "honeycombio_query_specification" "test" {
 resource "honeycombio_query" "test" {
   count = 2
 
-  dataset    = "%s"
+  dataset    = "%[1]s"
   query_json = data.honeycombio_query_specification.test[count.index].json
 }
 
 resource "honeycombio_query_annotation" "test" {
   count = 2
 
-  dataset     = "%s"
+  dataset     = "%[1]s"
   name        = "My annotated query"
   description = "My lovely description"
   query_id    = honeycombio_query.test[count.index].id
@@ -125,7 +223,7 @@ resource "honeycombio_board" "test" {
 
   query {
     caption             = "test query 0"
-    dataset             = "%s"
+    dataset             = "%[1]s"
     query_id            = honeycombio_query.test[0].id
     query_annotation_id = honeycombio_query_annotation.test[0].id
 
@@ -139,7 +237,7 @@ resource "honeycombio_board" "test" {
     query_id            = honeycombio_query.test[1].id
     query_annotation_id = honeycombio_query_annotation.test[1].id
   }
-}`, dataset, dataset, dataset)
+}`, dataset)
 }
 
 func testAccCheckBoardExists(t *testing.T, name string) resource.TestCheckFunc {