Skip to content

Commit

Permalink
pr things
Browse files Browse the repository at this point in the history
  • Loading branch information
obs-gh-catherman committed Dec 10, 2024
1 parent fddc827 commit bf39fc2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
31 changes: 30 additions & 1 deletion observe/resource_monitor_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,11 @@ func resourceMonitorV2() *schema.Resource {
Schema: map[string]*schema.Schema{
// note: subExpressions will be interesting to support. The UI currently does
// not support it, so we don't here either.
// When we add support for sub_expressions, it compare_terms will be ExactlyOneOf with that.
"compare_terms": { // [MonitorV2ComparisonTerm!]
Type: schema.TypeList,
Optional: true,
Required: true,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"comparison": { // [MonitorV2Comparison!]!
Expand Down Expand Up @@ -1386,3 +1388,30 @@ func newMonitorV2ActionAndRelation(path string, data *schema.ResourceData) (*gql

return &result, nil
}

func newMonitorV2ComparisonExpressionInput(path string, data *schema.ResourceData) (input *gql.MonitorV2ComparisonExpressionInput, diags diag.Diagnostics) {
input = &gql.MonitorV2ComparisonExpressionInput{
// AND is implied until the UI supports OR
Operator: gql.MonitorV2BooleanOperatorAnd,
}

for i := range data.Get(fmt.Sprintf("%scompare_terms", path)).([]interface{}) {
condPath := fmt.Sprintf("%scompare_terms.%d.", path, i)

term := gql.MonitorV2ComparisonTermInput{}
if c, d := newMonitorV2ComparisonInput(fmt.Sprintf("%scomparison.0.", condPath), data); d.HasError() {
return nil, d
} else {
term.Comparison = *c
}
if c, d := newMonitorV2ColumnInput(fmt.Sprintf("%scolumn.0.", condPath), data); d.HasError() {
return nil, d
} else {
term.Column = *c
}

input.CompareTerms = append(input.CompareTerms, term)
}

return
}
27 changes: 0 additions & 27 deletions observe/resource_monitor_v2_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,33 +306,6 @@ func monitorV2FlattenWebhookHeader(gqlHeader gql.MonitorV2WebhookHeader) interfa
return header
}

func newMonitorV2ComparisonExpressionInput(path string, data *schema.ResourceData) (input *gql.MonitorV2ComparisonExpressionInput, diags diag.Diagnostics) {
input = &gql.MonitorV2ComparisonExpressionInput{
// AND is implied until the UI supports OR
Operator: gql.MonitorV2BooleanOperatorAnd,
}

for i := range data.Get(fmt.Sprintf("%scompare_terms", path)).([]interface{}) {
condPath := fmt.Sprintf("%scompare_terms.%d.", path, i)

term := gql.MonitorV2ComparisonTermInput{}
if c, d := newMonitorV2ComparisonInput(fmt.Sprintf("%scomparison.0.", condPath), data); d.HasError() {
return nil, d
} else {
term.Comparison = *c
}
if c, d := newMonitorV2ColumnInput(fmt.Sprintf("%scolumn.0.", condPath), data); d.HasError() {
return nil, d
} else {
term.Column = *c
}

input.CompareTerms = append(input.CompareTerms, term)
}

return
}

func newMonitorV2ActionInput(path string, data *schema.ResourceData) (input *gql.MonitorV2ActionInput, diags diag.Diagnostics) {
// required
actionType := toCamel(data.Get(fmt.Sprintf("%stype", path)).(string))
Expand Down
1 change: 1 addition & 0 deletions observe/resource_monitor_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func TestAccObserveMonitorV2MultipleActionsEmailViaOneShot(t *testing.T) {
resource.TestCheckResourceAttr("observe_monitor_v2.first", "actions.0.send_reminders_interval", "10m0s"),
resource.TestCheckResourceAttr("observe_monitor_v2.first", "actions.1.send_reminders_interval", "20m0s"),
resource.TestCheckResourceAttr("observe_monitor_v2.first", "actions.1.conditions.0.compare_terms.0.comparison.0.compare_fn", "equal"),
resource.TestCheckResourceAttr("observe_monitor_v2.first", "actions.1.conditions.0.compare_terms.0.comparison.0.value_string.0", "test"),
resource.TestCheckResourceAttr("observe_monitor_v2.first", "actions.1.conditions.0.compare_terms.0.column.0.column_path.0.name", "description"),
),
},
Expand Down

0 comments on commit bf39fc2

Please sign in to comment.