Skip to content

Commit

Permalink
Migrate resource pagerduty_schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed May 3, 2024
1 parent 1129196 commit 4a64b82
Show file tree
Hide file tree
Showing 5 changed files with 3,277 additions and 18 deletions.
1 change: 1 addition & 0 deletions pagerduty/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func Provider(isMux bool) *schema.Provider {
delete(p.DataSourcesMap, "pagerduty_business_service")

delete(p.ResourcesMap, "pagerduty_business_service")
delete(p.ResourcesMap, "pagerduty_schedule")
}

p.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
Expand Down
18 changes: 0 additions & 18 deletions pagerdutyplugin/data_source_pagerduty_extension_schema_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package pagerduty

import (
"context"
"fmt"
"testing"

"github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)
Expand Down Expand Up @@ -56,19 +54,3 @@ data "pagerduty_extension_schema" "foo" {
name = "ServiceNow (v7)"
}
`

func testAccCheckPagerDutyScheduleDestroy(s *terraform.State) error {
for _, r := range s.RootModule().Resources {
if r.Type != "pagerduty_schedule" {
continue
}

ctx := context.Background()
opts := pagerduty.GetScheduleOptions{}
if _, err := testAccProvider.client.GetScheduleWithContext(ctx, r.Primary.ID, opts); err == nil {
return fmt.Errorf("Schedule still exists")
}

}
return nil
}
53 changes: 53 additions & 0 deletions pagerdutyplugin/import_pagerduty_schedule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package pagerduty

import (
"context"
"fmt"
"testing"
"time"

"github.com/PagerDuty/go-pagerduty"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccPagerDutySchedule_import(t *testing.T) {
username := fmt.Sprintf("tf-%s", acctest.RandString(5))
email := fmt.Sprintf("%[email protected]", username)
schedule := fmt.Sprintf("tf-%s", acctest.RandString(5))
location := "Europe/Berlin"
t.Setenv(location)
start := testAccTimeNow().Add(24 * time.Hour).Round(1 * time.Hour).Format(time.RFC3339)
rotationVirtualStart := testAccTimeNow().Add(24 * time.Hour).Round(1 * time.Hour).Format(time.RFC3339)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(),
CheckDestroy: testAccCheckPagerDutyUserDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyScheduleConfig(username, email, schedule, location, start, rotationVirtualStart),
},
{
ResourceName: "pagerduty_schedule.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckPagerDutyUserDestroy(s *terraform.State) error {
for _, r := range s.RootModule().Resources {
if r.Type != "pagerduty_user" {
continue
}

ctx := context.Background()
if _, err := testAccProvider.client.GetUserWithContext(ctx, r.Primary.ID, &pagerduty.GetUserOptions{}); err == nil {
return fmt.Errorf("User still exists")
}
}
return nil
}
Loading

0 comments on commit 4a64b82

Please sign in to comment.