@@ -40,7 +40,7 @@ import (
4040)
4141
4242// Currently, due to incorrect types in the API, the maximum recursion level for child routes is set to 1.
43- // Once this is fixed, the value should be set to 10.
43+ // Once this is fixed, the value should be set to 10 and toRoutePayload needs to be adjusted, to support it .
4444const childRouteMaxRecursionLevel = 1
4545
4646// Ensure the implementation satisfies the expected interfaces.
@@ -2086,7 +2086,7 @@ func toRoutePayload(ctx context.Context, routeTF *mainRouteModel) (*observabilit
20862086 }
20872087
20882088 var groupByPayload * []string
2089- var childRoutesPayload * []observability.CreateAlertConfigRoutePayloadRoutesInner
2089+ var childRoutesPayload * []observability.UpdateAlertConfigsPayloadRouteRoutesInner
20902090
20912091 if ! routeTF .GroupBy .IsNull () && ! routeTF .GroupBy .IsUnknown () {
20922092 groupByPayload = & []string {}
@@ -2124,14 +2124,14 @@ func toRoutePayload(ctx context.Context, routeTF *mainRouteModel) (*observabilit
21242124 }
21252125 }
21262126
2127- childRoutesList := []observability.CreateAlertConfigRoutePayloadRoutesInner {}
2127+ childRoutesList := []observability.UpdateAlertConfigsPayloadRouteRoutesInner {}
21282128 for i := range childRoutes {
21292129 childRoute := childRoutes [i ]
2130- childRoutePayload , err := toMiddleRoutesToPayload (ctx , & childRoute )
2130+ childRoutePayload , err := toChildRoutePayload (ctx , & childRoute )
21312131 if err != nil {
21322132 return nil , fmt .Errorf ("mapping child route: %w" , err )
21332133 }
2134- childRoutesList = append (childRoutesList , * toChildRoutePayload ( childRoutePayload ) )
2134+ childRoutesList = append (childRoutesList , * childRoutePayload )
21352135 }
21362136
21372137 childRoutesPayload = & childRoutesList
@@ -2147,15 +2147,14 @@ func toRoutePayload(ctx context.Context, routeTF *mainRouteModel) (*observabilit
21472147 }, nil
21482148}
21492149
2150- func toMiddleRoutesToPayload (ctx context.Context , routeTF * routeModelMiddle ) (* observability.UpdateAlertConfigsPayloadRoute , error ) {
2150+ func toChildRoutePayload (ctx context.Context , routeTF * routeModelMiddle ) (* observability.UpdateAlertConfigsPayloadRouteRoutesInner , error ) {
21512151 if routeTF == nil {
21522152 return nil , fmt .Errorf ("nil route model" )
21532153 }
21542154
21552155 var groupByPayload * []string
21562156 var matchPayload * map [string ]interface {}
21572157 var matchRegexPayload * map [string ]interface {}
2158- var childRoutesPayload * []observability.UpdateAlertConfigsPayloadRouteRoutesInner
21592158 var matchersPayload * []string
21602159
21612160 if ! utils .IsUndefined (routeTF .GroupBy ) {
@@ -2190,48 +2189,7 @@ func toMiddleRoutesToPayload(ctx context.Context, routeTF *routeModelMiddle) (*o
21902189 matchersPayload = matchersList
21912190 }
21922191
2193- if ! routeTF .Routes .IsNull () && ! routeTF .Routes .IsUnknown () {
2194- childRoutes := []routeModelMiddle {}
2195- diags := routeTF .Routes .ElementsAs (ctx , & childRoutes , false )
2196- if diags .HasError () {
2197- // If there is an error, we will try to map the child routes as if they are the last child routes
2198- // This is done because the last child routes in the recursion have a different structure (don't have the `routes` fields)
2199- // and need to be unpacked to a different struct (routeModelNoRoutes)
2200- lastChildRoutes := []routeModelNoRoutes {}
2201- diags = routeTF .Routes .ElementsAs (ctx , & lastChildRoutes , true )
2202- if diags .HasError () {
2203- return nil , fmt .Errorf ("mapping child routes: %w" , core .DiagsToError (diags ))
2204- }
2205- for i := range lastChildRoutes {
2206- childRoute := routeModelMiddle {
2207- GroupBy : lastChildRoutes [i ].GroupBy ,
2208- GroupInterval : lastChildRoutes [i ].GroupInterval ,
2209- GroupWait : lastChildRoutes [i ].GroupWait ,
2210- Match : lastChildRoutes [i ].Match ,
2211- MatchRegex : lastChildRoutes [i ].MatchRegex ,
2212- Matchers : lastChildRoutes [i ].Matchers ,
2213- Receiver : lastChildRoutes [i ].Receiver ,
2214- RepeatInterval : lastChildRoutes [i ].RepeatInterval ,
2215- Routes : types .ListNull (getRouteListType ()),
2216- }
2217- childRoutes = append (childRoutes , childRoute )
2218- }
2219- }
2220-
2221- childRoutesList := []observability.UpdateAlertConfigsPayloadRouteRoutesInner {}
2222- for i := range childRoutes {
2223- childRoute := childRoutes [i ]
2224- childRoutePayload , err := toMiddleRoutesToPayload (ctx , & childRoute )
2225- if err != nil {
2226- return nil , fmt .Errorf ("mapping child route: %w" , err )
2227- }
2228- childRoutesList = append (childRoutesList , * toChildRoutePayload (childRoutePayload ))
2229- }
2230-
2231- childRoutesPayload = & childRoutesList
2232- }
2233-
2234- return & observability.UpdateAlertConfigsPayloadRoute {
2192+ return & observability.UpdateAlertConfigsPayloadRouteRoutesInner {
22352193 GroupBy : groupByPayload ,
22362194 GroupInterval : conversion .StringValueToPointer (routeTF .GroupInterval ),
22372195 GroupWait : conversion .StringValueToPointer (routeTF .GroupWait ),
@@ -2240,27 +2198,10 @@ func toMiddleRoutesToPayload(ctx context.Context, routeTF *routeModelMiddle) (*o
22402198 Matchers : matchersPayload ,
22412199 Receiver : conversion .StringValueToPointer (routeTF .Receiver ),
22422200 RepeatInterval : conversion .StringValueToPointer (routeTF .RepeatInterval ),
2243- Routes : childRoutesPayload ,
2201+ // Routes: childRoutesPayload,
22442202 }, nil
22452203}
22462204
2247- func toChildRoutePayload (in * observability.UpdateAlertConfigsPayloadRoute ) * observability.UpdateAlertConfigsPayloadRouteRoutesInner {
2248- if in == nil {
2249- return nil
2250- }
2251- return & observability.UpdateAlertConfigsPayloadRouteRoutesInner {
2252- GroupBy : in .GroupBy ,
2253- GroupInterval : in .GroupInterval ,
2254- GroupWait : in .GroupWait ,
2255- Match : in .Match ,
2256- MatchRe : in .MatchRe ,
2257- Matchers : in .Matchers ,
2258- Receiver : in .Receiver ,
2259- RepeatInterval : in .RepeatInterval ,
2260- // Routes not currently supported
2261- }
2262- }
2263-
22642205func toGlobalConfigPayload (ctx context.Context , model * alertConfigModel ) (* observability.UpdateAlertConfigsPayloadGlobal , error ) {
22652206 globalConfigModel := globalConfigurationModel {}
22662207 diags := model .GlobalConfiguration .As (ctx , & globalConfigModel , basetypes.ObjectAsOptions {})
0 commit comments