Repository: honeycombio/terraform-provider-honeycombio
Pull request #159 (2022-05-05 00:18:46)

[triggers] Add alert_type field for Triggers
Adding a new attribute to Triggers, it will include the following changes:
- adding a new alert frequency to the Trigger structure

The current behaviors of triggers is an alert is sent on change. We are adding a the feature for the provider set alert on true for our triggers.

Read more about alert frequency here:
https://docs.honeycomb.io/working-with-your-data/triggers/#configuration

---
- To see the specific tasks where the Asana app for GitHub is being used, see below:
  - https://app.asana.com/0/0/1202136190006122


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 235c9cd..3eb59bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+# 0.6.0 (May 9, 2022)
+
+FEATURES:
+
+* *New Data Source*: `honeycombio_query_result` (#151)
+
+HOUSEKEEPING:
+
+* terraform-plugin-sdk upgraded from 2.14.0 to 2.15.0 (#161)
+
 # 0.5.0 (Apr 25, 2022)
 
 BUGFIXES:
diff --git a/README.md b/README.md
index f704c6e..593a8d2 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ terraform {
   required_providers {
     honeycombio = {
       source  = "honeycombio/honeycombio"
-      version = "~> 0.5.0"
+      version = "~> 0.6.0"
     }
   }
 }
diff --git a/client/trigger.go b/client/trigger.go
index 057623b..18cd2aa 100644
--- a/client/trigger.go
+++ b/client/trigger.go
@@ -58,6 +58,8 @@ type Trigger struct {
 	// be greater than 4 times the frequency.
 	Query   *QuerySpec `json:"query,omitempty"`
 	QueryID string     `json:"query_id,omitempty"`
+	// Alert Type. Describes scheduling behavior for triggers.
+	AlertType string `json:"alert_type,omitempty"`
 	// Threshold. This fild is required.
 	Threshold *TriggerThreshold `json:"threshold"`
 	// Frequency describes how often the trigger should run. Frequency is an
@@ -95,6 +97,12 @@ func TriggerThresholdOps() []TriggerThresholdOp {
 	}
 }
 
+// Allowed values for alert_type. | on_change is default
+const (
+	TriggerAlertTypeValueOnChange string = "on_change"
+	TriggerAlertTypeValueOnTrue   string = "on_true"
+)
+
 // TriggerRecipient represents a recipient that will receive a notification
 // when the trigger fires.
 //
@@ -179,6 +187,7 @@ func (t *Trigger) MarshalJSON() ([]byte, error) {
 			Description: t.Description,
 			Disabled:    t.Disabled,
 			QueryID:     t.QueryID,
+			AlertType:   t.AlertType,
 			Threshold:   t.Threshold,
 			Frequency:   t.Frequency,
 			Recipients:  t.Recipients,
diff --git a/docs/data-sources/query_result.md b/docs/data-sources/query_result.md
index 4c098ec..d033586 100644
--- a/docs/data-sources/query_result.md
+++ b/docs/data-sources/query_result.md
@@ -16,16 +16,11 @@ data "honeycombio_query_specification" "example" {
   }
 }
 
-resource "honeycombio_query" "example" {
+data "honeycombio_query_result" "example" {
   dataset    = var.dataset
   query_json = data.honeycombio_query_specification.example.json
 }
 
-data "honeycombio_query_result" "example" {
-  dataset  = var.dataset
-  query_id = honeycombio_query.example.id
-}
-
 output "event_count" {
   value = format(
     "There have been %d events in the last %d seconds.",
@@ -42,12 +37,13 @@ output "event_count" {
 The following arguments are supported:
 
 * `dataset` - (Required) The dataset this query is associated with.
-* `query_id` - (Required) The ID of the query that will be executed to obtain the result.
+* `query_json` - (Required) A JSON object describing the query according to the Query Specification. While the JSON can be constructed manually, it is easiest to use the honeycombio_query_specification data source.
 
 ## Attribute Reference
 
 In addition to all arguments above, the following attributes are exported:
 
+* `query_id` - The ID of the Query created and executed to obtain the result.
 * `query_url` - The permalink to the executed query's results.
 * `query_image_url` - The permalink to the visualization of the executed query's results.
 * `results` - The results of the executed query. This will be a list of maps, with each map's keys set to the breakdowns and calculations of the query. Due to a limitation of the Terraform Plugin SDK, all values are transformed into strings.
diff --git a/docs/data-sources/trigger_recipient.md b/docs/data-sources/trigger_recipient.md
index 3b859a5..d3f269c 100644
--- a/docs/data-sources/trigger_recipient.md
+++ b/docs/data-sources/trigger_recipient.md
@@ -1,6 +1,6 @@
 # Data Source: honeycombio_trigger_recipient
 
-Search the triggers of a dataset for a trigger recipient. The ID of the existing trigger recipient can be used when adding trigger recipients to new triggers. Specifying a trigger recipient by its ID is necessary when adding Slack recipients, since these can not be created using the API.
+Search the triggers of a dataset for a trigger recipient. The ID of the existing trigger recipient can be used when adding trigger recipients to new triggers.
 
 ## Example Usage
 
diff --git a/docs/index.md b/docs/index.md
index ddd19a0..4712d97 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -14,7 +14,7 @@ terraform {
   required_providers {
     honeycombio = {
       source  = "honeycombio/honeycombio"
-      version = "~> 0.5.0"
+      version = "~> 0.6.0"
     }
   }
 }
diff --git a/docs/resources/trigger.md b/docs/resources/trigger.md
index b5b99b8..19b31e5 100644
--- a/docs/resources/trigger.md
+++ b/docs/resources/trigger.md
@@ -35,6 +35,8 @@ resource "honeycombio_trigger" "example" {
 
   frequency = 600 // in seconds, 10 minutes
 
+  alert_type = "on_change" // on_change is default, on_true can refers to the "Alert on True" checkbox in the UI
+
   threshold {
     op    = ">"
     value = 1000
@@ -64,6 +66,7 @@ The following arguments are supported:
 * `description` - (Optional) Description of the trigger.
 * `disabled` - (Optional) The state of the trigger. If true, the trigger will not be run. Defaults to false.
 * `frequency` - (Optional) The interval (in seconds) in which to check the results of the query’s calculation against the threshold. Value must be divisible by 60 and between 60 and 86400 (between 1 minute and 1 day). Defaults to 900 (15 minutes).
+* `alert_type` - (Optional) The frequency for the alert to trigger. (`on_change` is the default behavior, `on_true` can also be selected)
 * `recipient` - (Optional) Zero or more configuration blocks (described below) with the recipients to notify when the trigger fires.
 
 -> **NOTE** The query used in a Trigger must follow a strict subset: a query must contain exactly one calcuation and may only contain `calculation`, `filter`, `filter_combination` and `breakdowns` fields. The query's duration cannot be more than four times the trigger's frequency.
diff --git a/example/board_via_query_result/main.tf b/example/board_via_query_result/main.tf
new file mode 100644
index 0000000..7cf80a4
--- /dev/null
+++ b/example/board_via_query_result/main.tf
@@ -0,0 +1,42 @@
+terraform {
+  required_providers {
+    honeycombio = {
+      source = "honeycombio/honeycombio"
+    }
+  }
+}
+
+variable "dataset" {
+  type = string
+}
+
+data "honeycombio_query_specification" "example" {
+  time_range = 7 * 86400 # last 7 days
+
+  calculation {
+    op = "COUNT"
+  }
+
+  breakdowns = ["service.name"]
+}
+
+
+data "honeycombio_query_result" "example" {
+  dataset    = var.dataset
+  query_json = data.honeycombio_query_specification.example.json
+}
+
+locals {
+  active_services = flatten(
+    [
+      for result in data.honeycombio_query_result.example.results : result["service.name"]
+    ]
+  )
+}
+
+# generate a board for each service seen in the last 7 days
+resource "honeycombio_board" "services" {
+  for_each = toset(local.active_services)
+
+  name = format("%s board", each.key)
+}
diff --git a/go.mod b/go.mod
index edb6bc2..b55d31f 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.17
 
 require (
 	github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
-	github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0
+	github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0
 	github.com/joho/godotenv v1.4.0
 	github.com/stretchr/testify v1.7.1
 )
@@ -16,7 +16,7 @@ require (
 	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/fatih/color v1.7.0 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
-	github.com/google/go-cmp v0.5.7 // indirect
+	github.com/google/go-cmp v0.5.8 // indirect
 	github.com/hashicorp/errwrap v1.0.0 // indirect
 	github.com/hashicorp/go-checkpoint v0.5.0 // indirect
 	github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -25,13 +25,13 @@ require (
 	github.com/hashicorp/go-plugin v1.4.3 // indirect
 	github.com/hashicorp/go-uuid v1.0.3 // indirect
 	github.com/hashicorp/go-version v1.4.0 // indirect
-	github.com/hashicorp/hc-install v0.3.1 // indirect
-	github.com/hashicorp/hcl/v2 v2.11.1 // indirect
+	github.com/hashicorp/hc-install v0.3.2 // indirect
+	github.com/hashicorp/hcl/v2 v2.12.0 // indirect
 	github.com/hashicorp/logutils v1.0.0 // indirect
 	github.com/hashicorp/terraform-exec v0.16.1 // indirect
 	github.com/hashicorp/terraform-json v0.13.0 // indirect
 	github.com/hashicorp/terraform-plugin-go v0.9.0 // indirect
-	github.com/hashicorp/terraform-plugin-log v0.3.0 // indirect
+	github.com/hashicorp/terraform-plugin-log v0.4.0 // indirect
 	github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect
 	github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
 	github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
@@ -40,7 +40,7 @@ require (
 	github.com/mitchellh/copystructure v1.2.0 // indirect
 	github.com/mitchellh/go-testing-interface v1.14.1 // indirect
 	github.com/mitchellh/go-wordwrap v1.0.0 // indirect
-	github.com/mitchellh/mapstructure v1.4.3 // indirect
+	github.com/mitchellh/mapstructure v1.5.0 // indirect
 	github.com/mitchellh/reflectwalk v1.0.2 // indirect
 	github.com/oklog/run v1.0.0 // indirect
 	github.com/pmezard/go-difflib v1.0.0 // indirect
diff --git a/go.sum b/go.sum
index 2ffebb4..bf7e3d7 100644
--- a/go.sum
+++ b/go.sum
@@ -86,8 +86,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
 github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
+github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
+github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
 github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
@@ -114,10 +115,11 @@ github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09
 github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
 github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4=
 github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
-github.com/hashicorp/hc-install v0.3.1 h1:VIjllE6KyAI1A244G8kTaHXy+TL5/XYzvrtFi8po/Yk=
 github.com/hashicorp/hc-install v0.3.1/go.mod h1:3LCdWcCDS1gaHC9mhHCGbkYfoY6vdsKohGjugbZdZak=
-github.com/hashicorp/hcl/v2 v2.11.1 h1:yTyWcXcm9XB0TEkyU/JCRU6rYy4K+mgLtzn2wlrJbcc=
-github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
+github.com/hashicorp/hc-install v0.3.2 h1:oiQdJZvXmkNcRcEOOfM5n+VTsvNjWQeOjfAoO6dKSH8=
+github.com/hashicorp/hc-install v0.3.2/go.mod h1:xMG6Tr8Fw1WFjlxH0A9v61cW15pFwgEGqEz0V4jisHs=
+github.com/hashicorp/hcl/v2 v2.12.0 h1:PsYxySWpMD4KPaoJLnsHwtK5Qptvj/4Q6s0t4sUxZf4=
+github.com/hashicorp/hcl/v2 v2.12.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
 github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
 github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
 github.com/hashicorp/terraform-exec v0.16.1 h1:NAwZFJW2L2SaCBVZoVaH8LPImLOGbPLkSHy0IYbs2uE=
@@ -126,10 +128,11 @@ github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniy
 github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk=
 github.com/hashicorp/terraform-plugin-go v0.9.0 h1:FvLY/3z4SNVatPZdoFcyrlNbCar+WyyOTv5X4Tp+WZc=
 github.com/hashicorp/terraform-plugin-go v0.9.0/go.mod h1:EawBkgjBWNf7jiKnVoyDyF39OSV+u6KUX+Y73EPj3oM=
-github.com/hashicorp/terraform-plugin-log v0.3.0 h1:NPENNOjaJSVX0f7JJTl4f/2JKRPQ7S2ZN9B4NSqq5kA=
 github.com/hashicorp/terraform-plugin-log v0.3.0/go.mod h1:EjueSP/HjlyFAsDqt+okpCPjkT4NDynAe32AeDC4vps=
-github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0 h1:GZ8NY74rxObB7QHE/JiuBW0ZEr04rlplR/TVrkgw3rw=
-github.com/hashicorp/terraform-plugin-sdk/v2 v2.14.0/go.mod h1:+m4FDQ8h1ulz7zpWtqmZn2JSZQDXUVibhUShbkQVId4=
+github.com/hashicorp/terraform-plugin-log v0.4.0 h1:F3eVnm8r2EfQCe2k9blPIiF/r2TT01SHijXnS7bujvc=
+github.com/hashicorp/terraform-plugin-log v0.4.0/go.mod h1:9KclxdunFownr4pIm1jdmwKRmE4d6HVG2c9XDq47rpg=
+github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0 h1:9fjPgCenJqnbjo95SDcbJ+YdLyEC1N35cwKWcRWhJTQ=
+github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0/go.mod h1:hLa0sTiySU/AWEgV2GxJh0/pQIqcCmm30IPja9N9lTg=
 github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 h1:1FGtlkJw87UsTMg5s8jrekrHmUPUJaMcu6ELiVhQrNw=
 github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co=
 github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
@@ -175,8 +178,8 @@ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp
 github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
 github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
 github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
-github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
-github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
+github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
+github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
 github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@@ -298,7 +301,6 @@ golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed/go.mod h1:njjCfa9FT2d7l9Bc
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
diff --git a/honeycombio/data_source_query_result.go b/honeycombio/data_source_query_result.go
index 2db2741..1f301a0 100644
--- a/honeycombio/data_source_query_result.go
+++ b/honeycombio/data_source_query_result.go
@@ -2,11 +2,13 @@ package honeycombio
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 
 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
 	honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
+	"github.com/honeycombio/terraform-provider-honeycombio/honeycombio/internal/verify"
 )
 
 func dataSourceHoneycombioQueryResult() *schema.Resource {
@@ -18,11 +20,17 @@ func dataSourceHoneycombioQueryResult() *schema.Resource {
 				Type:     schema.TypeString,
 				Required: true,
 			},
+			"query_json": {
+				Type:             schema.TypeString,
+				Required:         true,
+				ValidateDiagFunc: validateQueryJSON(),
+				DiffSuppressFunc: verify.SuppressEquivJSONDiffs,
+			},
+			// outputs
 			"query_id": {
 				Type:     schema.TypeString,
-				Required: true,
+				Computed: true,
 			},
-			// outputs
 			"query_url": {
 				Type:     schema.TypeString,
 				Computed: true,
@@ -43,12 +51,20 @@ func dataSourceHoneycombioQueryResult() *schema.Resource {
 }
 
 func dataSourceHoneycombioQueryResultRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
+	var querySpec honeycombio.QuerySpec
 	client := meta.(*honeycombio.Client)
-
 	dataset := d.Get("dataset").(string)
-	queryID := d.Get("query_id").(string)
 
-	queryResult, err := client.QueryResults.Create(ctx, dataset, &honeycombio.QueryResultRequest{ID: queryID})
+	err := json.Unmarshal([]byte(d.Get("query_json").(string)), &querySpec)
+	if err != nil {
+		return diag.FromErr(err)
+	}
+	query, err := client.Queries.Create(ctx, dataset, &querySpec)
+	if err != nil {
+		return diag.FromErr(err)
+	}
+
+	queryResult, err := client.QueryResults.Create(ctx, dataset, &honeycombio.QueryResultRequest{ID: *query.ID})
 	if err != nil {
 		return diag.FromErr(err)
 	}
@@ -71,6 +87,12 @@ func dataSourceHoneycombioQueryResultRead(ctx context.Context, d *schema.Resourc
 	}
 
 	d.SetId(queryResult.ID)
+	queryJSON, err := encodeQuery(query)
+	if err != nil {
+		return diag.FromErr(err)
+	}
+	d.Set("query_json", queryJSON)
+	d.Set("query_id", *query.ID)
 	d.Set("query_url", queryResult.Links.Url)
 	d.Set("graph_image_url", queryResult.Links.GraphUrl)
 	d.Set("results", results)
diff --git a/honeycombio/resource_trigger.go b/honeycombio/resource_trigger.go
index a652196..2c08c6a 100644
--- a/honeycombio/resource_trigger.go
+++ b/honeycombio/resource_trigger.go
@@ -45,6 +45,12 @@ func newTrigger() *schema.Resource {
 				Type:     schema.TypeString,
 				Required: true,
 			},
+			"alert_type": {
+				Type:         schema.TypeString,
+				Optional:     true,
+				Default:      "on_change",
+				ValidateFunc: validation.StringInSlice([]string{"on_change", "on_true"}, false),
+			},
 			"threshold": {
 				Type:     schema.TypeList,
 				Required: true,
@@ -156,6 +162,7 @@ func resourceTriggerRead(ctx context.Context, d *schema.ResourceData, meta inter
 	d.Set("description", t.Description)
 	d.Set("disabled", t.Disabled)
 	d.Set("query_id", t.QueryID)
+	d.Set("alert_type", t.AlertType)
 
 	err = d.Set("threshold", flattenTriggerThreshold(t.Threshold))
 	if err != nil {
@@ -213,6 +220,7 @@ func expandTrigger(d *schema.ResourceData) (*honeycombio.Trigger, error) {
 		Description: d.Get("description").(string),
 		Disabled:    d.Get("disabled").(bool),
 		QueryID:     d.Get("query_id").(string),
+		AlertType:   d.Get("alert_type").(string),
 		Threshold:   expandTriggerThreshold(d.Get("threshold").([]interface{})),
 		Frequency:   d.Get("frequency").(int),
 		Recipients:  expandTriggerRecipients(d.Get("recipient").([]interface{})),


Test patch:
diff --git a/client/trigger_test.go b/client/trigger_test.go
index 8f94cff..9e52105 100644
--- a/client/trigger_test.go
+++ b/client/trigger_test.go
@@ -50,6 +50,7 @@ func TestTriggers(t *testing.T) {
 				Op:    TriggerThresholdOpGreaterThan,
 				Value: 10000,
 			},
+			AlertType: "on_change",
 			Recipients: []TriggerRecipient{
 				{
 					Type:   TriggerRecipientTypeEmail,
@@ -71,12 +72,16 @@ func TestTriggers(t *testing.T) {
 		// copy IDs before asserting equality
 		data.ID = trigger.ID
 		data.QueryID = trigger.QueryID
+		data.AlertType = trigger.AlertType
 		for i := range trigger.Recipients {
 			data.Recipients[i].ID = trigger.Recipients[i].ID
 		}
 		// set default time range
 		data.Query.TimeRange = IntPtr(300)
 
+		// set the default alert type
+		data.AlertType = TriggerAlertTypeValueOnChange
+
 		assert.Equal(t, data, trigger)
 	})
 
@@ -97,11 +102,14 @@ func TestTriggers(t *testing.T) {
 	t.Run("Update", func(t *testing.T) {
 		trigger.Description = "A new description"
 
+		// update the alert_type to on_true / this is a simple validation that this field works
+		trigger.AlertType = TriggerAlertTypeValueOnTrue
+
 		result, err := c.Triggers.Update(ctx, dataset, trigger)
 
 		// copy IDs before asserting equality
 		trigger.QueryID = result.QueryID
-
+		trigger.AlertType = result.AlertType
 		assert.NoError(t, err)
 		assert.Equal(t, trigger, result)
 	})
diff --git a/honeycombio/data_source_query_result_test.go b/honeycombio/data_source_query_result_test.go
index 5f7e19b..9461c2b 100644
--- a/honeycombio/data_source_query_result_test.go
+++ b/honeycombio/data_source_query_result_test.go
@@ -40,8 +40,8 @@ resource "honeycombio_query" "test" {
 }
 
 data "honeycombio_query_result" "test" {
-  dataset  = "%s"
-  query_id = honeycombio_query.test.id
+  dataset    = "%s"
+  query_json = data.honeycombio_query_specification.test.json
 }
 
 output "results" {
diff --git a/honeycombio/resource_trigger_test.go b/honeycombio/resource_trigger_test.go
index 339f082..7ce099c 100644
--- a/honeycombio/resource_trigger_test.go
+++ b/honeycombio/resource_trigger_test.go
@@ -26,6 +26,8 @@ func TestAccHoneycombioTrigger_basic(t *testing.T) {
 					testAccCheckTriggerExists(t, "honeycombio_trigger.test", &triggerBefore),
 					testAccCheckTriggerAttributes(&triggerBefore),
 					resource.TestCheckResourceAttr("honeycombio_trigger.test", "frequency", "900"),
+					resource.TestCheckResourceAttr("honeycombio_trigger.test", "frequency", "900"),
+					resource.TestCheckResourceAttr("honeycombio_trigger.test", "alert_type", "on_change"),
 				),
 			},
 			{
@@ -79,6 +81,10 @@ func testAccCheckTriggerAttributes(t *honeycombio.Trigger) resource.TestCheckFun
 			return fmt.Errorf("bad frequency: %d", t.Frequency)
 		}
 
+		if t.AlertType != "on_change" {
+			return fmt.Errorf("bad AlertType: %s | should be on_change", t.AlertType)
+		}
+
 		return nil
 	}
 }
@@ -136,6 +142,8 @@ resource "honeycombio_trigger" "test" {
     value = 1000
   }
 
+  alert_type = "on_change"
+
   recipient {
     type   = "slack"
     target = "#test2"
@@ -189,6 +197,8 @@ resource "honeycombio_trigger" "test" {
 
   query_id = honeycombio_query.test.id
 
+  alert_type = "on_change"
+  
   threshold {
     op    = ">"
     value = 100
@@ -242,6 +252,8 @@ resource "honeycombio_trigger" "test" {
 
   query_id = honeycombio_query.test.id
 
+  alert_type = "on_change"
+
   threshold {
     op    = ">"
     value = 100
@@ -270,6 +282,8 @@ resource "honeycombio_trigger" "test" {
 
   query_id = honeycombio_query.test.id
 
+  alert_type = "on_change"
+
   threshold {
     op    = ">"
     value = 100