Skip to content

Commit

Permalink
Merge pull request #896 from cjgajard/tpf-team
Browse files Browse the repository at this point in the history
Migrate pack #3 of datasources and resources to terraform plugin framework
  • Loading branch information
imjaroiswebdev authored Jul 4, 2024
2 parents 57656bc + cae8aab commit 955eef9
Show file tree
Hide file tree
Showing 16 changed files with 806 additions and 227 deletions.
175 changes: 0 additions & 175 deletions pagerduty/data_source_pagerduty_license.go

This file was deleted.

62 changes: 62 additions & 0 deletions pagerduty/data_source_pagerduty_licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/heimweh/go-pagerduty/pagerduty"
)

// Deprecated: Migrated to pagerdutyplugin.dataSourceLicenses. Kept for testing purposes.
func dataSourcePagerDutyLicenses() *schema.Resource {
return &schema.Resource{
Read: dataSourcePagerDutyLicensesRead,
Expand Down Expand Up @@ -91,3 +92,64 @@ func flattenLicense(l *pagerduty.License) map[string]interface{} {

return license
}

var licenseSchema = map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"summary": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"role_group": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"current_value": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"allocations_available": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"valid_roles": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"self": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"html_url": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
}
1 change: 1 addition & 0 deletions pagerduty/data_source_pagerduty_priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/heimweh/go-pagerduty/pagerduty"
)

// Deprecated: Migrated to pagerdutyplugin.dataSourcePriority. Kept for testing purposes.
func dataSourcePagerDutyPriority() *schema.Resource {
return &schema.Resource{
Read: dataSourcePagerDutyPriorityRead,
Expand Down
4 changes: 3 additions & 1 deletion pagerduty/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func Provider(isMux bool) *schema.Provider {
"pagerduty_schedule": dataSourcePagerDutySchedule(),
"pagerduty_user": dataSourcePagerDutyUser(),
"pagerduty_users": dataSourcePagerDutyUsers(),
"pagerduty_license": dataSourcePagerDutyLicense(),
"pagerduty_licenses": dataSourcePagerDutyLicenses(),
"pagerduty_user_contact_method": dataSourcePagerDutyUserContactMethod(),
"pagerduty_team": dataSourcePagerDutyTeam(),
Expand Down Expand Up @@ -155,11 +154,14 @@ func Provider(isMux bool) *schema.Provider {

if isMux {
delete(p.DataSourcesMap, "pagerduty_business_service")
delete(p.DataSourcesMap, "pagerduty_licenses")
delete(p.DataSourcesMap, "pagerduty_priority")
delete(p.DataSourcesMap, "pagerduty_service")
delete(p.DataSourcesMap, "pagerduty_service_integration")

delete(p.ResourcesMap, "pagerduty_addon")
delete(p.ResourcesMap, "pagerduty_business_service")
delete(p.ResourcesMap, "pagerduty_team")
}

p.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
Expand Down
26 changes: 26 additions & 0 deletions pagerduty/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/heimweh/go-pagerduty/pagerduty"
)

Expand Down Expand Up @@ -189,6 +190,7 @@ resource "pagerduty_service" "foo" {
}
`, username, email, escalationPolicy, service)
}

func testAccCheckPagerDutyProviderAuthWithMultipleMethodsConfig(username, email, escalationPolicy, service string) string {
return fmt.Sprintf(`
provider "pagerduty" {
Expand Down Expand Up @@ -331,3 +333,27 @@ func testAccGetPagerDutyAccountDomain(t *testing.T) string {
}
return accountDomain
}

func testAccCheckPagerDutyTeamDestroy(s *terraform.State) error {
client, _ := testAccProvider.Meta().(*Config).Client()
for _, r := range s.RootModule().Resources {
if r.Type != "pagerduty_team" {
continue
}

if _, _, err := client.Teams.Get(r.Primary.ID); err == nil {
return fmt.Errorf("Team still exists")
}

}
return nil
}

func testAccCheckPagerDutyTeamConfig(team string) string {
return fmt.Sprintf(`
resource "pagerduty_team" "foo" {
name = "%s"
description = "foo"
}`, team)
}
1 change: 1 addition & 0 deletions pagerduty/resource_pagerduty_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/heimweh/go-pagerduty/pagerduty"
)

// Deprecated: Migrated to pagerdutyplugin.resourceTeam. Kept for testing purposes.
func resourcePagerDutyTeam() *schema.Resource {
return &schema.Resource{
Create: resourcePagerDutyTeamCreate,
Expand Down
Loading

0 comments on commit 955eef9

Please sign in to comment.