@@ -414,6 +414,98 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
414414 })
415415}
416416
417+ func TestAccSumologicMonitorsLibraryMonitorFolder_update (t * testing.T ) {
418+ var monitorsLibraryMonitor MonitorsLibraryMonitor
419+ testNameSuffix := acctest .RandString (16 )
420+
421+ testName := "terraform_test_monitor_" + testNameSuffix
422+ testType := "MonitorsLibraryMonitor"
423+ testMonitorType := "Logs"
424+ //testAlertName := "Alert from {{Name}}"
425+ folder1tfResourceKey := "sumologic_monitor_folder.tf_folder_01"
426+ folder2tfResourceKey := "sumologic_monitor_folder.tf_folder_02"
427+
428+ resource .Test (t , resource.TestCase {
429+ PreCheck : func () { testAccPreCheck (t ) },
430+ Providers : testAccProviders ,
431+ CheckDestroy : testAccCheckMonitorsLibraryMonitorDestroy (monitorsLibraryMonitor ),
432+ Steps : []resource.TestStep {
433+ {
434+ Config : testAccSumologicMonitorsLibraryMonitorFolderUpdate (testNameSuffix , folder1tfResourceKey ),
435+ Check : resource .ComposeTestCheckFunc (
436+ testAccCheckMonitorsLibraryMonitorExists ("sumologic_monitor.test" , & monitorsLibraryMonitor , t ),
437+ testAccCheckMonitorsLibraryMonitorAttributes ("sumologic_monitor.test" ),
438+ resource .TestCheckResourceAttr ("sumologic_monitor.test" , "monitor_type" , testMonitorType ),
439+ resource .TestCheckResourceAttr ("sumologic_monitor.test" , "name" , testName ),
440+ resource .TestCheckResourceAttr ("sumologic_monitor.test" , "type" , testType ),
441+ testAccCheckMonitorsLibraryMonitorFolderMatch ("sumologic_monitor.test" , folder1tfResourceKey , t ),
442+ ),
443+ },
444+ {
445+ Config : testAccSumologicMonitorsLibraryMonitorFolderUpdate (testNameSuffix , folder2tfResourceKey ),
446+ Check : resource .ComposeTestCheckFunc (
447+ testAccCheckMonitorsLibraryMonitorExists ("sumologic_monitor.test" , & monitorsLibraryMonitor , t ),
448+ testAccCheckMonitorsLibraryMonitorAttributes ("sumologic_monitor.test" ),
449+ resource .TestCheckResourceAttr ("sumologic_monitor.test" , "monitor_type" , testMonitorType ),
450+ resource .TestCheckResourceAttr ("sumologic_monitor.test" , "name" , testName ),
451+ resource .TestCheckResourceAttr ("sumologic_monitor.test" , "type" , testType ),
452+ testAccCheckMonitorsLibraryMonitorFolderMatch ("sumologic_monitor.test" , folder2tfResourceKey , t ),
453+ ),
454+ },
455+ },
456+ })
457+ }
458+
459+ func testAccCheckMonitorsLibraryMonitorFolderMatch (monitorName string , folderName string , t * testing.T ) resource.TestCheckFunc {
460+ return func (s * terraform.State ) error {
461+ //fetching monitor information
462+ monitorResource , ok := s .RootModule ().Resources [monitorName ]
463+ if ! ok {
464+ //need this so that we don't get an unused import error for strconv in some cases
465+ return fmt .Errorf ("Error = %s. MonitorsLibraryMonitor not found: %s" , strconv .FormatBool (ok ), monitorName )
466+ }
467+
468+ //need this so that we don't get an unused import error for strings in some cases
469+ if strings .EqualFold (monitorResource .Primary .ID , "" ) {
470+ return fmt .Errorf ("MonitorsLibraryMonitor ID is not set" )
471+ }
472+
473+ monitorResourceId := monitorResource .Primary .ID
474+
475+ client := testAccProvider .Meta ().(* Client )
476+ monitorsLibraryMonitor , err := client .MonitorsRead (monitorResourceId )
477+
478+ if err != nil {
479+ return fmt .Errorf ("MonitorsLibraryMonitor %s not found" , monitorResourceId )
480+ }
481+
482+ //fetching monitor folder information
483+ folderResource , ok := s .RootModule ().Resources [folderName ]
484+ if ! ok {
485+ //need this so that we don't get an unused import error for strconv in some cases
486+ return fmt .Errorf ("Error = %s. MonitorsLibraryFolder not found: %s" , strconv .FormatBool (ok ), folderName )
487+ }
488+
489+ //need this so that we don't get an unused import error for strings in some cases
490+ if strings .EqualFold (folderResource .Primary .ID , "" ) {
491+ return fmt .Errorf ("MonitorsLibraryFolder ID is not set" )
492+ }
493+
494+ folderResourceId := folderResource .Primary .ID
495+ monitorsLibraryFolder , err := client .MonitorsRead (folderResourceId )
496+ if err != nil {
497+ return fmt .Errorf ("MonitorsLibraryFolder%s not found" , monitorResourceId )
498+ }
499+
500+ //checkig if the monitor parent id matches to the correct folder id
501+ if monitorsLibraryMonitor .ParentID != monitorsLibraryFolder .ID {
502+ return fmt .Errorf ("Parent Id should be %s but %s" , monitorsLibraryFolder .ID , monitorsLibraryMonitor .ParentID )
503+ }
504+
505+ return nil
506+ }
507+ }
508+
417509func testAccCheckMonitorsLibraryMonitorDestroy (monitorsLibraryMonitor MonitorsLibraryMonitor ) resource.TestCheckFunc {
418510 return func (s * terraform.State ) error {
419511 client := testAccProvider .Meta ().(* Client )
@@ -573,6 +665,62 @@ resource "sumologic_monitor" "test" {
573665}` , testName )
574666}
575667
668+ func testAccSumologicMonitorsLibraryMonitorFolderUpdate (testName string , parentIdTFString string ) string {
669+ return fmt .Sprintf (`
670+ resource "sumologic_monitor_folder" "tf_folder_01" {
671+ name = "tf_test_folder_01_%s"
672+ description = "1st folder"
673+ }
674+ resource "sumologic_monitor_folder" "tf_folder_02" {
675+ name = "tf_test_folder_02_%s"
676+ description = "1st folder"
677+ }
678+ resource "sumologic_monitor" "test" {
679+ name = "terraform_test_monitor_%s"
680+ description = "terraform_test_monitor_description"
681+ type = "MonitorsLibraryMonitor"
682+ is_disabled = false
683+ content_type = "Monitor"
684+ monitor_type = "Logs"
685+ evaluation_delay = "8m"
686+ queries {
687+ row_id = "A"
688+ query = "_sourceCategory=monitor-manager info"
689+ }
690+ triggers {
691+ threshold_type = "GreaterThan"
692+ threshold = 40.0
693+ time_range = "30m"
694+ occurrence_type = "ResultCount"
695+ trigger_source = "AllResults"
696+ trigger_type = "Critical"
697+ detection_method = "StaticCondition"
698+ }
699+ triggers {
700+ threshold_type = "LessThanOrEqual"
701+ threshold = 40.0
702+ time_range = "30m"
703+ occurrence_type = "ResultCount"
704+ trigger_source = "AllResults"
705+ trigger_type = "ResolvedCritical"
706+ detection_method = "StaticCondition"
707+ }
708+ notifications {
709+ notification {
710+ connection_type = "Email"
711+ recipients = ["[email protected] "] 712+ subject = "test tf monitor"
713+ time_zone = "PST"
714+ message_body = "test"
715+ }
716+ run_for_trigger_types = ["Critical", "ResolvedCritical"]
717+ }
718+ playbook = "This is an updated test playbook"
719+ alert_name = "Updated Alert from {{Name}}"
720+ parent_id = %s.id
721+ }` , testName , testName , testName , parentIdTFString )
722+ }
723+
576724func exampleMonitorWithTriggerCondition (
577725 testName string ,
578726 monitorType string ,
0 commit comments