@@ -5,15 +5,14 @@ package datasources
55import (
66 "context"
77
8- "github.com/hashicorp/terraform-plugin-framework/attr"
98 "github.com/hashicorp/terraform-plugin-framework/datasource"
109 "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
11- "github.com/hashicorp/terraform-plugin-framework/diag"
1210 "github.com/hashicorp/terraform-plugin-framework/types"
1311
1412 "github.com/stacklet/terraform-provider-stacklet/internal/api"
1513 "github.com/stacklet/terraform-provider-stacklet/internal/errors"
1614 "github.com/stacklet/terraform-provider-stacklet/internal/models"
15+ "github.com/stacklet/terraform-provider-stacklet/internal/modelupdate"
1716 "github.com/stacklet/terraform-provider-stacklet/internal/providerdata"
1817 tftypes "github.com/stacklet/terraform-provider-stacklet/internal/types"
1918)
@@ -411,207 +410,30 @@ func (d *reportGroupDataSource) Read(ctx context.Context, req datasource.ReadReq
411410 data .GroupBy = tftypes .StringsList (reportGroup .GroupBy )
412411 data .UseMessageSettings = types .BoolValue (reportGroup .UseMessageSettings )
413412
414- emailDeliverySettings , diags := tftypes .ObjectList [models.EmailDeliverySettings ](
415- reportGroup .EmailDeliverySettings (),
416- func (entry api.EmailDeliverySettings ) (map [string ]attr.Value , diag.Diagnostics ) {
417- recipients , diags := tftypes .ObjectList [models.Recipient ](
418- entry .Recipients ,
419- func (entry api.Recipient ) (map [string ]attr.Value , diag.Diagnostics ) {
420- return map [string ]attr.Value {
421- "account_owner" : types .BoolPointerValue (entry .AccountOwner ),
422- "event_owner" : types .BoolPointerValue (entry .EventOwner ),
423- "resource_owner" : types .BoolPointerValue (entry .ResourceOwner ),
424- "tag" : types .StringPointerValue (entry .Tag ),
425- "value" : types .StringPointerValue (entry .Value ),
426- }, nil
427- },
428- )
429- if diags .HasError () {
430- return map [string ]attr.Value {}, diags
431- }
413+ updater := modelupdate .NewReportGroupUpdater (* reportGroup )
432414
433- return map [string ]attr.Value {
434- "cc" : tftypes .StringsList (entry .CC ),
435- "first_match_only" : types .BoolPointerValue (entry .FirstMatchOnly ),
436- "format" : types .StringPointerValue (entry .Format ),
437- "from" : types .StringPointerValue (entry .FromEmail ),
438- "priority" : types .StringPointerValue (entry .Priority ),
439- "recipients" : recipients ,
440- "subject" : types .StringValue (entry .Subject ),
441- "template" : types .StringValue (entry .Template ),
442- }, nil
443- },
444- )
415+ emailDeliverySettings , diags := updater .EmailDeliverySettings ()
445416 resp .Diagnostics .Append (diags ... )
446- if resp .Diagnostics .HasError () {
447- return
448- }
449417 data .EmailDeliverySettings = emailDeliverySettings
450418
451- slackDeliverySettings , diags := tftypes .ObjectList [models.SlackDeliverySettings ](
452- reportGroup .SlackDeliverySettings (),
453- func (entry api.SlackDeliverySettings ) (map [string ]attr.Value , diag.Diagnostics ) {
454- recipients , diags := tftypes .ObjectList [models.Recipient ](
455- entry .Recipients ,
456- func (entry api.Recipient ) (map [string ]attr.Value , diag.Diagnostics ) {
457- return map [string ]attr.Value {
458- "account_owner" : types .BoolPointerValue (entry .AccountOwner ),
459- "event_owner" : types .BoolPointerValue (entry .EventOwner ),
460- "resource_owner" : types .BoolPointerValue (entry .ResourceOwner ),
461- "tag" : types .StringPointerValue (entry .Tag ),
462- "value" : types .StringPointerValue (entry .Value ),
463- }, nil
464- },
465- )
466- if diags .HasError () {
467- return map [string ]attr.Value {}, diags
468- }
469-
470- return map [string ]attr.Value {
471- "first_match_only" : types .BoolPointerValue (entry .FirstMatchOnly ),
472- "recipients" : recipients ,
473- "template" : types .StringValue (entry .Template ),
474- }, nil
475- },
476- )
419+ slackDeliverySettings , diags := updater .SlackDeliverySettings ()
477420 resp .Diagnostics .Append (diags ... )
478- if resp .Diagnostics .HasError () {
479- return
480- }
481421 data .SlackDeliverySettings = slackDeliverySettings
482422
483- teamsDeliverySettings , diags := tftypes .ObjectList [models.TeamsDeliverySettings ](
484- reportGroup .TeamsDeliverySettings (),
485- func (entry api.TeamsDeliverySettings ) (map [string ]attr.Value , diag.Diagnostics ) {
486- recipients , diags := tftypes .ObjectList [models.Recipient ](
487- entry .Recipients ,
488- func (entry api.Recipient ) (map [string ]attr.Value , diag.Diagnostics ) {
489- return map [string ]attr.Value {
490- "account_owner" : types .BoolPointerValue (entry .AccountOwner ),
491- "event_owner" : types .BoolPointerValue (entry .EventOwner ),
492- "resource_owner" : types .BoolPointerValue (entry .ResourceOwner ),
493- "tag" : types .StringPointerValue (entry .Tag ),
494- "value" : types .StringPointerValue (entry .Value ),
495- }, nil
496- },
497- )
498- if diags .HasError () {
499- return map [string ]attr.Value {}, diags
500- }
501-
502- return map [string ]attr.Value {
503- "first_match_only" : types .BoolPointerValue (entry .FirstMatchOnly ),
504- "recipients" : recipients ,
505- "template" : types .StringValue (entry .Template ),
506- }, nil
507- },
508- )
423+ teamsDeliverySettings , diags := updater .TeamsDeliverySettings ()
509424 resp .Diagnostics .Append (diags ... )
510- if resp .Diagnostics .HasError () {
511- return
512- }
513425 data .TeamsDeliverySettings = teamsDeliverySettings
514426
515- servicenowDeliverySettings , diags := tftypes .ObjectList [models.ServiceNowDeliverySettings ](
516- reportGroup .ServiceNowDeliverySettings (),
517- func (entry api.ServiceNowDeliverySettings ) (map [string ]attr.Value , diag.Diagnostics ) {
518- recipients , diags := tftypes .ObjectList [models.Recipient ](
519- entry .Recipients ,
520- func (entry api.Recipient ) (map [string ]attr.Value , diag.Diagnostics ) {
521- return map [string ]attr.Value {
522- "account_owner" : types .BoolPointerValue (entry .AccountOwner ),
523- "event_owner" : types .BoolPointerValue (entry .EventOwner ),
524- "resource_owner" : types .BoolPointerValue (entry .ResourceOwner ),
525- "tag" : types .StringPointerValue (entry .Tag ),
526- "value" : types .StringPointerValue (entry .Value ),
527- }, nil
528- },
529- )
530- if diags .HasError () {
531- return map [string ]attr.Value {}, diags
532- }
533-
534- return map [string ]attr.Value {
535- "first_match_only" : types .BoolPointerValue (entry .FirstMatchOnly ),
536- "impact" : types .StringValue (entry .Impact ),
537- "recipients" : recipients ,
538- "short_description" : types .StringValue (entry .ShortDescription ),
539- "template" : types .StringValue (entry .Template ),
540- "urgency" : types .StringValue (entry .Urgency ),
541- }, nil
542- },
543- )
427+ servicenowDeliverySettings , diags := updater .ServiceNowDeliverySettings ()
544428 resp .Diagnostics .Append (diags ... )
545- if resp .Diagnostics .HasError () {
546- return
547- }
548429 data .ServiceNowDeliverySettings = servicenowDeliverySettings
549430
550- jiraDeliverySettings , diags := tftypes .ObjectList [models.JiraDeliverySettings ](
551- reportGroup .JiraDeliverySettings (),
552- func (entry api.JiraDeliverySettings ) (map [string ]attr.Value , diag.Diagnostics ) {
553- recipients , diags := tftypes .ObjectList [models.Recipient ](
554- entry .Recipients ,
555- func (entry api.Recipient ) (map [string ]attr.Value , diag.Diagnostics ) {
556- return map [string ]attr.Value {
557- "account_owner" : types .BoolPointerValue (entry .AccountOwner ),
558- "event_owner" : types .BoolPointerValue (entry .EventOwner ),
559- "resource_owner" : types .BoolPointerValue (entry .ResourceOwner ),
560- "tag" : types .StringPointerValue (entry .Tag ),
561- "value" : types .StringPointerValue (entry .Value ),
562- }, nil
563- },
564- )
565- if diags .HasError () {
566- return map [string ]attr.Value {}, diags
567- }
568-
569- return map [string ]attr.Value {
570- "first_match_only" : types .BoolPointerValue (entry .FirstMatchOnly ),
571- "recipients" : recipients ,
572- "template" : types .StringValue (entry .Template ),
573- "description" : types .StringValue (entry .Description ),
574- "project" : types .StringValue (entry .Project ),
575- "summary" : types .StringValue (entry .Summary ),
576- }, nil
577- },
578- )
431+ jiraDeliverySettings , diags := updater .JiraDeliverySettings ()
579432 resp .Diagnostics .Append (diags ... )
580- if resp .Diagnostics .HasError () {
581- return
582- }
583433 data .JiraDeliverySettings = jiraDeliverySettings
584434
585- symphonyDeliverySettings , diags := tftypes .ObjectList [models.SymphonyDeliverySettings ](
586- reportGroup .SymphonyDeliverySettings (),
587- func (entry api.SymphonyDeliverySettings ) (map [string ]attr.Value , diag.Diagnostics ) {
588- recipients , diags := tftypes .ObjectList [models.Recipient ](
589- entry .Recipients ,
590- func (entry api.Recipient ) (map [string ]attr.Value , diag.Diagnostics ) {
591- return map [string ]attr.Value {
592- "account_owner" : types .BoolPointerValue (entry .AccountOwner ),
593- "event_owner" : types .BoolPointerValue (entry .EventOwner ),
594- "resource_owner" : types .BoolPointerValue (entry .ResourceOwner ),
595- "tag" : types .StringPointerValue (entry .Tag ),
596- "value" : types .StringPointerValue (entry .Value ),
597- }, nil
598- },
599- )
600- if diags .HasError () {
601- return map [string ]attr.Value {}, diags
602- }
603-
604- return map [string ]attr.Value {
605- "first_match_only" : types .BoolPointerValue (entry .FirstMatchOnly ),
606- "recipients" : recipients ,
607- "template" : types .StringValue (entry .Template ),
608- }, nil
609- },
610- )
435+ symphonyDeliverySettings , diags := updater .SymphonyDeliverySettings ()
611436 resp .Diagnostics .Append (diags ... )
612- if resp .Diagnostics .HasError () {
613- return
614- }
615437 data .SymphonyDeliverySettings = symphonyDeliverySettings
616438
617439 resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
0 commit comments