Skip to content

Commit

Permalink
Migrate data source automation actions runnner
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed Jul 9, 2024
1 parent 98416c2 commit 10554ab
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 101 deletions.
97 changes: 0 additions & 97 deletions pagerduty/data_source_pagerduty_automation_actions_runner.go

This file was deleted.

1 change: 0 additions & 1 deletion pagerduty/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func Provider(isMux bool) *schema.Provider {
"pagerduty_event_orchestration_integration": dataSourcePagerDutyEventOrchestrationIntegration(),
"pagerduty_event_orchestration_global_cache_variable": dataSourcePagerDutyEventOrchestrationGlobalCacheVariable(),
"pagerduty_event_orchestration_service_cache_variable": dataSourcePagerDutyEventOrchestrationServiceCacheVariable(),
"pagerduty_automation_actions_runner": dataSourcePagerDutyAutomationActionsRunner(),
"pagerduty_incident_workflow": dataSourcePagerDutyIncidentWorkflow(),
"pagerduty_incident_custom_field": dataSourcePagerDutyIncidentCustomField(),
"pagerduty_team_members": dataSourcePagerDutyTeamMembers(),
Expand Down
104 changes: 104 additions & 0 deletions pagerdutyplugin/data_source_pagerduty_automation_actions_runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package pagerduty

import (
"context"
"fmt"
"log"
"time"

"github.com/PagerDuty/go-pagerduty"
"github.com/PagerDuty/terraform-provider-pagerduty/util"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
)

type dataSourceAutomationActionsRunner struct{ client *pagerduty.Client }

var _ datasource.DataSourceWithConfigure = (*dataSourceAutomationActionsRunner)(nil)

func (*dataSourceAutomationActionsRunner) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_automation_actions_runner"
}

func (*dataSourceAutomationActionsRunner) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{Required: true},
"name": schema.StringAttribute{Computed: true},
"type": schema.StringAttribute{Computed: true},
"runner_type": schema.StringAttribute{Computed: true},
"creation_time": schema.StringAttribute{Computed: true},
"last_seen": schema.StringAttribute{Computed: true, Optional: true},
"description": schema.StringAttribute{Computed: true, Optional: true},
"runbook_base_uri": schema.StringAttribute{Computed: true, Optional: true},
},
}
}

func (d *dataSourceAutomationActionsRunner) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

func (d *dataSourceAutomationActionsRunner) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
log.Println("[INFO] Reading PagerDuty automation actions runner")

var searchID types.String
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("id"), &searchID)...)
if resp.Diagnostics.HasError() {
return
}

var model dataSourceAutomationActionsRunnerModel
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
runner, err := d.client.GetAutomationActionsRunnerWithContext(ctx, searchID.ValueString())
if err != nil {
if util.IsBadRequestError(err) {
return retry.NonRetryableError(err)
}
return retry.RetryableError(err)
}

model = dataSourceAutomationActionsRunnerModel{
ID: types.StringValue(runner.ID),
Name: types.StringValue(runner.Name),
Type: types.StringValue(runner.Type),
RunnerType: types.StringValue(runner.RunnerType),
CreationTime: types.StringValue(runner.CreationTime),
}

if runner.Description != "" {
model.Description = types.StringValue(runner.Description)
}

if runner.RunbookBaseURI != "" {
model.RunbookBaseURI = types.StringValue(runner.RunbookBaseURI)
}

if runner.LastSeen != "" {
model.LastSeen = types.StringValue(runner.LastSeen)
}
return nil
})
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error reading PagerDuty automation actions runner %s", searchID),
err.Error(),
)
return
}
resp.Diagnostics.Append(resp.State.Set(ctx, &model)...)
}

type dataSourceAutomationActionsRunnerModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Type types.String `tfsdk:"type"`
RunnerType types.String `tfsdk:"runner_type"`
CreationTime types.String `tfsdk:"creation_time"`
LastSeen types.String `tfsdk:"last_seen"`
Description types.String `tfsdk:"description"`
RunbookBaseURI types.String `tfsdk:"runbook_base_uri"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestAccDataSourcePagerDutyAutomationActionsRunner_Basic(t *testing.T) {
name := fmt.Sprintf("tf-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testAccDataSourcePagerDutyAutomationActionsRunnerConfig(name),
Expand Down
3 changes: 2 additions & 1 deletion pagerdutyplugin/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ func (p *Provider) Schema(_ context.Context, _ provider.SchemaRequest, resp *pro
func (p *Provider) DataSources(_ context.Context) [](func() datasource.DataSource) {
return [](func() datasource.DataSource){
func() datasource.DataSource { return &dataSourceAutomationActionsAction{} },
func() datasource.DataSource { return &dataSourceAutomationActionsRunner{} },
func() datasource.DataSource { return &dataSourceBusinessService{} },
func() datasource.DataSource { return &dataSourceExtensionSchema{} },
func() datasource.DataSource { return &dataSourceIntegration{} },
func() datasource.DataSource { return &dataSourceLicense{} },
func() datasource.DataSource { return &dataSourceLicenses{} },
func() datasource.DataSource { return &dataSourceLicense{} },
func() datasource.DataSource { return &dataSourcePriority{} },
func() datasource.DataSource { return &dataSourceService{} },
func() datasource.DataSource { return &dataSourceStandardsResourceScores{} },
Expand Down

0 comments on commit 10554ab

Please sign in to comment.