Skip to content

Commit

Permalink
Merge pull request PagerDuty#812 from cjgajard/tpf-datasource-standar…
Browse files Browse the repository at this point in the history
…ds-resources-scores

[CSGI-2422] [CSGI-2427] Add datasource standards resource scores and standards resources scores
  • Loading branch information
imjaroiswebdev authored Feb 8, 2024
2 parents 7ea8000 + 4348821 commit 341be4f
Show file tree
Hide file tree
Showing 231 changed files with 3,882 additions and 6,453 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/hashicorp/terraform-exec v0.20.0
github.com/hashicorp/terraform-json v0.20.0
github.com/hashicorp/terraform-plugin-framework v1.5.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-go v0.20.0
github.com/hashicorp/terraform-plugin-mux v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/hashicorp/terraform-json v0.20.0 h1:cJcvn4gIOTi0SD7pIy+xiofV1zFA3hza+
github.com/hashicorp/terraform-json v0.20.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk=
github.com/hashicorp/terraform-plugin-framework v1.5.0 h1:8kcvqJs/x6QyOFSdeAyEgsenVOUeC/IyKpi2ul4fjTg=
github.com/hashicorp/terraform-plugin-framework v1.5.0/go.mod h1:6waavirukIlFpVpthbGd2PUNYaFedB0RwW3MDzJ/rtc=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
github.com/hashicorp/terraform-plugin-go v0.20.0 h1:oqvoUlL+2EUbKNsJbIt3zqqZ7wi6lzn4ufkn/UA51xQ=
github.com/hashicorp/terraform-plugin-go v0.20.0/go.mod h1:Rr8LBdMlY53a3Z/HpP+ZU3/xCDqtKNCkeI9qOyT10QE=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
Expand Down
10 changes: 5 additions & 5 deletions pagerduty/data_source_pagerduty_automation_actions_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -106,17 +106,17 @@ func dataSourcePagerDutyAutomationActionsActionRead(d *schema.ResourceData, meta

log.Printf("[INFO] Reading PagerDuty AutomationActionsAction")

return resource.Retry(2*time.Minute, func() *resource.RetryError {
return retry.Retry(2*time.Minute, func() *retry.RetryError {
automationActionsAction, _, err := client.AutomationActionsAction.Get(d.Get("id").(string))
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

// Delaying retry by 30s as recommended by PagerDuty
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit
time.Sleep(30 * time.Second)
return resource.RetryableError(err)
return retry.RetryableError(err)
}

d.SetId(automationActionsAction.ID)
Expand All @@ -131,7 +131,7 @@ func dataSourcePagerDutyAutomationActionsActionRead(d *schema.ResourceData, meta

f_adr := flattenActionDataReference(automationActionsAction.ActionDataReference)
if err := d.Set("action_data_reference", f_adr); err != nil {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

if automationActionsAction.ModifyTime != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourcePagerDutyAutomationActionsAction_Basic(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pagerduty/data_source_pagerduty_automation_actions_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -61,17 +61,17 @@ func dataSourcePagerDutyAutomationActionsRunnerRead(d *schema.ResourceData, meta

log.Printf("[INFO] Reading PagerDuty automation actions runner")

return resource.Retry(2*time.Minute, func() *resource.RetryError {
return retry.Retry(2*time.Minute, func() *retry.RetryError {
runner, _, err := client.AutomationActionsRunner.Get(d.Get("id").(string))
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

// Delaying retry by 30s as recommended by PagerDuty
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit
time.Sleep(30 * time.Second)
return resource.RetryableError(err)
return retry.RetryableError(err)
}

d.SetId(runner.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourcePagerDutyAutomationActionsRunner_Basic(t *testing.T) {
Expand Down
11 changes: 5 additions & 6 deletions pagerduty/data_source_pagerduty_business_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)
Expand Down Expand Up @@ -38,17 +38,17 @@ func dataSourcePagerDutyBusinessServiceRead(d *schema.ResourceData, meta interfa

searchName := d.Get("name").(string)

return resource.Retry(5*time.Minute, func() *resource.RetryError {
return retry.Retry(5*time.Minute, func() *retry.RetryError {
resp, _, err := client.BusinessServices.List()
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

// Delaying retry by 30s as recommended by PagerDuty
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit
time.Sleep(30 * time.Second)
return resource.RetryableError(err)
return retry.RetryableError(err)
}

var found *pagerduty.BusinessService
Expand All @@ -61,7 +61,7 @@ func dataSourcePagerDutyBusinessServiceRead(d *schema.ResourceData, meta interfa
}

if found == nil {
return resource.NonRetryableError(
return retry.NonRetryableError(
fmt.Errorf("Unable to locate any business service with the name: %s", searchName),
)
}
Expand All @@ -72,5 +72,4 @@ func dataSourcePagerDutyBusinessServiceRead(d *schema.ResourceData, meta interfa

return nil
})

}
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_business_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourcePagerDutyBusinessService_Basic(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions pagerduty/data_source_pagerduty_escalation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)
Expand Down Expand Up @@ -38,17 +38,17 @@ func dataSourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interf
Query: searchName,
}

return resource.Retry(5*time.Minute, func() *resource.RetryError {
return retry.Retry(5*time.Minute, func() *retry.RetryError {
resp, _, err := client.EscalationPolicies.List(o)
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

// Delaying retry by 30s as recommended by PagerDuty
// https://developer.pagerduty.com/docs/rest-api-v2/rate-limiting/#what-are-possible-workarounds-to-the-events-api-rate-limit
time.Sleep(30 * time.Second)
return resource.RetryableError(err)
return retry.RetryableError(err)
}

var found *pagerduty.EscalationPolicy
Expand All @@ -61,7 +61,7 @@ func dataSourcePagerDutyEscalationPolicyRead(d *schema.ResourceData, meta interf
}

if found == nil {
return resource.NonRetryableError(
return retry.NonRetryableError(
fmt.Errorf("Unable to locate any escalation policy with the name: %s", searchName),
)
}
Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_escalation_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourcePagerDutyEscalationPolicy_Basic(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions pagerduty/data_source_pagerduty_event_orchestration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)
Expand Down Expand Up @@ -67,14 +67,14 @@ func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta inte

searchName := d.Get("name").(string)

return resource.Retry(5*time.Minute, func() *resource.RetryError {
return retry.Retry(5*time.Minute, func() *retry.RetryError {
resp, _, err := client.EventOrchestrations.List()
if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

return resource.RetryableError(err)
return retry.RetryableError(err)
}

var found *pagerduty.EventOrchestration
Expand All @@ -87,7 +87,7 @@ func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta inte
}

if found == nil {
return resource.NonRetryableError(
return retry.NonRetryableError(
fmt.Errorf("Unable to locate any Event Orchestration with the name: %s", searchName),
)
}
Expand All @@ -96,7 +96,7 @@ func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta inte
// since the list ndpoint does not return it
orch, _, err := client.EventOrchestrations.Get(found.ID)
if err != nil {
return resource.RetryableError(err)
return retry.RetryableError(err)
}

d.SetId(orch.ID)
Expand Down
19 changes: 9 additions & 10 deletions pagerduty/data_source_pagerduty_event_orchestration_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)
Expand Down Expand Up @@ -82,16 +82,16 @@ func getEventOrchestrationIntegrationById(ctx context.Context, d *schema.Resourc
return diag.FromErr(err)
}

retryErr := resource.RetryContext(ctx, 2*time.Minute, func() *resource.RetryError {
retryErr := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
log.Printf("[INFO] Reading Integration data source by ID '%s' for PagerDuty Event Orchestration '%s'", id, oid)

if integration, _, err := client.EventOrchestrationIntegrations.GetContext(ctx, oid, id); err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

time.Sleep(30 * time.Second)
return resource.RetryableError(err)
return retry.RetryableError(err)
} else if integration != nil {
d.SetId(integration.ID)
setEventOrchestrationIntegrationProps(d, integration)
Expand All @@ -116,18 +116,17 @@ func getEventOrchestrationIntegrationByLabel(ctx context.Context, d *schema.Reso
return diag.FromErr(err)
}

retryErr := resource.RetryContext(ctx, 2*time.Minute, func() *resource.RetryError {
retryErr := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
log.Printf("[INFO] Reading Integration data source by label '%s' for PagerDuty Event Orchestration '%s'", lbl, oid)

resp, _, err := client.EventOrchestrationIntegrations.ListContext(ctx, oid)

if err != nil {
if isErrCode(err, http.StatusBadRequest) {
return resource.NonRetryableError(err)
return retry.NonRetryableError(err)
}

time.Sleep(30 * time.Second)
return resource.RetryableError(err)
return retry.RetryableError(err)
}

var matches []*pagerduty.EventOrchestrationIntegration
Expand All @@ -141,13 +140,13 @@ func getEventOrchestrationIntegrationByLabel(ctx context.Context, d *schema.Reso
count := len(matches)

if count == 0 {
return resource.NonRetryableError(
return retry.NonRetryableError(
fmt.Errorf("Unable to find an Integration on Event Orchestration '%s' with label '%s'", oid, lbl),
)
}

if count > 1 {
return resource.NonRetryableError(
return retry.NonRetryableError(
fmt.Errorf("Ambiguous Integration label: '%s'. Found %v Integrations with this label on Event Orchestration '%s'. Please use the Integration ID instead or make Integration labels unique within Event Orchestration.", lbl, count, oid),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourcePagerDutyEventOrchestrationIntegration_Basic(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pagerduty/data_source_pagerduty_event_orchestration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourcePagerDutyEventOrchestration_Basic(t *testing.T) {
Expand Down
Loading

0 comments on commit 341be4f

Please sign in to comment.