@@ -2,15 +2,26 @@ package oncall
22
33import (
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+
1425func 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