Skip to content

Commit 1326a83

Browse files
areh-devSergey ArefevIldar Iskhakovjulienduchesne
authored
Grafana OnCall: routing_type attribute for grafana_oncall_route resource (support Jinja2 templates) (#892)
* ResourceRoute: routing_type attribute * ResourceRoute: routing_type attribute docs * ResourceRoute: fix routing_type attribute description * fix lint & docs * Upgrade github.com/grafana/amixr-api-go-client to v0.0.8 * Set `regex` as a default * Generate docs --------- Co-authored-by: Sergey Arefev <[email protected]> Co-authored-by: Ildar Iskhakov <[email protected]> Co-authored-by: Julien Duchesne <[email protected]>
1 parent 569af5f commit 1326a83

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/resources/oncall_route.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ resource "grafana_oncall_route" "example_route" {
5959
### Optional
6060

6161
- `msteams` (Block List, Max: 1) MS teams-specific settings for a route. (see [below for nested schema](#nestedblock--msteams))
62+
- `routing_type` (String) The type of route. Can be jinja2, regex Defaults to `regex`.
6263
- `slack` (Block List, Max: 1) Slack-specific settings for a route. (see [below for nested schema](#nestedblock--slack))
6364
- `telegram` (Block List, Max: 1) Telegram-specific settings for a route. (see [below for nested schema](#nestedblock--telegram))
6465

internal/resources/oncall/resource_route.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@ package oncall
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67
"net/http"
8+
"strings"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
711

812
onCallAPI "github.com/grafana/amixr-api-go-client"
913
"github.com/grafana/terraform-provider-grafana/internal/common"
1014
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1115
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1216
)
1317

18+
var routeTypeOptions = []string{
19+
"jinja2",
20+
"regex",
21+
}
22+
23+
var routeTypeOptionsVerbal = strings.Join(routeTypeOptions, ", ")
24+
1425
func ResourceRoute() *schema.Resource {
1526
return &schema.Resource{
1627
Description: `
@@ -41,6 +52,13 @@ func ResourceRoute() *schema.Resource {
4152
Required: true,
4253
Description: "The position of the route (starts from 0).",
4354
},
55+
"routing_type": {
56+
Type: schema.TypeString,
57+
Optional: true,
58+
ValidateFunc: validation.StringInSlice(routeTypeOptions, false),
59+
Default: "regex",
60+
Description: fmt.Sprintf("The type of route. Can be %s", routeTypeOptionsVerbal),
61+
},
4462
"routing_regex": {
4563
Type: schema.TypeString,
4664
Required: true,
@@ -118,6 +136,7 @@ func ResourceRouteCreate(ctx context.Context, d *schema.ResourceData, m interfac
118136

119137
integrationID := d.Get("integration_id").(string)
120138
escalationChainID := d.Get("escalation_chain_id").(string)
139+
routingType := d.Get("routing_type").(string)
121140
routingRegex := d.Get("routing_regex").(string)
122141
position := d.Get("position").(int)
123142
slack := d.Get("slack").([]interface{})
@@ -127,6 +146,7 @@ func ResourceRouteCreate(ctx context.Context, d *schema.ResourceData, m interfac
127146
createOptions := &onCallAPI.CreateRouteOptions{
128147
IntegrationId: integrationID,
129148
EscalationChainId: escalationChainID,
149+
RoutingType: routingType,
130150
RoutingRegex: routingRegex,
131151
Position: &position,
132152
ManualOrder: true,
@@ -160,6 +180,7 @@ func ResourceRouteRead(ctx context.Context, d *schema.ResourceData, m interface{
160180

161181
d.Set("integration_id", route.IntegrationId)
162182
d.Set("escalation_chain_id", route.EscalationChainId)
183+
d.Set("routing_type", route.RoutingType)
163184
d.Set("routing_regex", route.RoutingRegex)
164185
d.Set("position", route.Position)
165186

@@ -184,6 +205,7 @@ func ResourceRouteUpdate(ctx context.Context, d *schema.ResourceData, m interfac
184205
client := m.(*common.Client).OnCallClient
185206

186207
escalationChainID := d.Get("escalation_chain_id").(string)
208+
routingType := d.Get("routing_type").(string)
187209
routingRegex := d.Get("routing_regex").(string)
188210
position := d.Get("position").(int)
189211
slack := d.Get("slack").([]interface{})
@@ -192,6 +214,7 @@ func ResourceRouteUpdate(ctx context.Context, d *schema.ResourceData, m interfac
192214

193215
updateOptions := &onCallAPI.UpdateRouteOptions{
194216
EscalationChainId: escalationChainID,
217+
RoutingType: routingType,
195218
RoutingRegex: routingRegex,
196219
Position: &position,
197220
ManualOrder: true,

0 commit comments

Comments
 (0)