diff --git a/docs/resources/oncall_route.md b/docs/resources/oncall_route.md index 727721fb4..036853c71 100644 --- a/docs/resources/oncall_route.md +++ b/docs/resources/oncall_route.md @@ -59,6 +59,7 @@ resource "grafana_oncall_route" "example_route" { ### Optional - `msteams` (Block List, Max: 1) MS teams-specific settings for a route. (see [below for nested schema](#nestedblock--msteams)) +- `routing_type` (String) The type of route. Can be jinja2, regex Defaults to `regex`. - `slack` (Block List, Max: 1) Slack-specific settings for a route. (see [below for nested schema](#nestedblock--slack)) - `telegram` (Block List, Max: 1) Telegram-specific settings for a route. (see [below for nested schema](#nestedblock--telegram)) diff --git a/internal/resources/oncall/resource_route.go b/internal/resources/oncall/resource_route.go index b33328478..901a9dda2 100644 --- a/internal/resources/oncall/resource_route.go +++ b/internal/resources/oncall/resource_route.go @@ -2,8 +2,12 @@ package oncall import ( "context" + "fmt" "log" "net/http" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" onCallAPI "github.com/grafana/amixr-api-go-client" "github.com/grafana/terraform-provider-grafana/internal/common" @@ -11,6 +15,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +var routeTypeOptions = []string{ + "jinja2", + "regex", +} + +var routeTypeOptionsVerbal = strings.Join(routeTypeOptions, ", ") + func ResourceRoute() *schema.Resource { return &schema.Resource{ Description: ` @@ -41,6 +52,13 @@ func ResourceRoute() *schema.Resource { Required: true, Description: "The position of the route (starts from 0).", }, + "routing_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(routeTypeOptions, false), + Default: "regex", + Description: fmt.Sprintf("The type of route. Can be %s", routeTypeOptionsVerbal), + }, "routing_regex": { Type: schema.TypeString, Required: true, @@ -118,6 +136,7 @@ func ResourceRouteCreate(ctx context.Context, d *schema.ResourceData, m interfac integrationID := d.Get("integration_id").(string) escalationChainID := d.Get("escalation_chain_id").(string) + routingType := d.Get("routing_type").(string) routingRegex := d.Get("routing_regex").(string) position := d.Get("position").(int) slack := d.Get("slack").([]interface{}) @@ -127,6 +146,7 @@ func ResourceRouteCreate(ctx context.Context, d *schema.ResourceData, m interfac createOptions := &onCallAPI.CreateRouteOptions{ IntegrationId: integrationID, EscalationChainId: escalationChainID, + RoutingType: routingType, RoutingRegex: routingRegex, Position: &position, ManualOrder: true, @@ -160,6 +180,7 @@ func ResourceRouteRead(ctx context.Context, d *schema.ResourceData, m interface{ d.Set("integration_id", route.IntegrationId) d.Set("escalation_chain_id", route.EscalationChainId) + d.Set("routing_type", route.RoutingType) d.Set("routing_regex", route.RoutingRegex) d.Set("position", route.Position) @@ -184,6 +205,7 @@ func ResourceRouteUpdate(ctx context.Context, d *schema.ResourceData, m interfac client := m.(*common.Client).OnCallClient escalationChainID := d.Get("escalation_chain_id").(string) + routingType := d.Get("routing_type").(string) routingRegex := d.Get("routing_regex").(string) position := d.Get("position").(int) slack := d.Get("slack").([]interface{}) @@ -192,6 +214,7 @@ func ResourceRouteUpdate(ctx context.Context, d *schema.ResourceData, m interfac updateOptions := &onCallAPI.UpdateRouteOptions{ EscalationChainId: escalationChainID, + RoutingType: routingType, RoutingRegex: routingRegex, Position: &position, ManualOrder: true,