Skip to content

Commit

Permalink
refactor all functions to use new generic read function (#524)
Browse files Browse the repository at this point in the history
* refactor all functions to use new generic read function

* lint
  • Loading branch information
rocktavious authored Oct 24, 2024
1 parent 8cfb959 commit 61a1c05
Show file tree
Hide file tree
Showing 76 changed files with 348 additions and 1,045 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.14.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/opslevel/opslevel-go/v2024 v2024.10.15
github.com/relvacode/iso8601 v1.4.0
github.com/relvacode/iso8601 v1.5.0
golang.org/x/net v0.30.0
)

require (
github.com/coder/websocket v1.8.12 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand All @@ -25,13 +25,13 @@ require (
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/terraform-plugin-go v0.24.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/hasura/go-graphql-client v0.13.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -47,9 +47,9 @@ require (
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)

// replace github.com/opslevel/opslevel-go/v2024 => ./submodules/opslevel-go
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
Expand Down Expand Up @@ -44,8 +44,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0=
github.com/hashicorp/go-plugin v1.6.2 h1:zdGAEd0V1lCaU0u+MxWQhtSDQmahpkwOun8U8EiRVog=
github.com/hashicorp/go-plugin v1.6.2/go.mod h1:CkgLQ5CZqNmdL9U9JzM532t8ZiYQ35+pj3b1FD37R0Q=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
Expand All @@ -62,8 +62,8 @@ github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTV
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
github.com/hasura/go-graphql-client v0.13.1 h1:kKbjhxhpwz58usVl+Xvgah/TDha5K2akNTRQdsEHN6U=
github.com/hasura/go-graphql-client v0.13.1/go.mod h1:k7FF7h53C+hSNFRG3++DdVZWIuHdCaTbI7siTJ//zGQ=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
Expand Down Expand Up @@ -100,8 +100,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/relvacode/iso8601 v1.4.0 h1:GsInVSEJfkYuirYFxa80nMLbH2aydgZpIf52gYZXUJs=
github.com/relvacode/iso8601 v1.4.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=
github.com/relvacode/iso8601 v1.5.0 h1:hM+cirGvOz6gKuUEqimr5TH3tiQiVOuc2QIO+nI5fY4=
github.com/relvacode/iso8601 v1.5.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=
github.com/rocktavious/autopilot/v2023 v2023.12.7 h1:v0FieSwgpdZXfCfpffuVullbZ2jTDFPweijeCj1/bfY=
github.com/rocktavious/autopilot/v2023 v2023.12.7/go.mod h1:BxaQ/N7Y6Rpcy04W1ovQVSeNYPHKhUVyKMdQ3a6kbK4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand Down Expand Up @@ -137,12 +137,12 @@ golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo=
google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5 changes: 1 addition & 4 deletions opslevel/datasource_opslevel_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ func (d *DomainDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
}

func (d *DomainDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data domainDataSourceModelWithIdentifier

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
data := read[domainDataSourceModelWithIdentifier](ctx, &resp.Diagnostics, req.Config)

if resp.Diagnostics.HasError() {
return
Expand Down
9 changes: 0 additions & 9 deletions opslevel/datasource_opslevel_domains_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ func (d *DomainDataSourcesAll) Schema(ctx context.Context, req datasource.Schema
}

func (d *DomainDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel DomainDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)

if resp.Diagnostics.HasError() {
return
}

domains, err := d.client.ListDomains(nil)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read domain, got error: %s", err))
Expand Down
5 changes: 1 addition & 4 deletions opslevel/datasource_opslevel_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ func (d *FilterDataSource) Schema(ctx context.Context, req datasource.SchemaRequ
}

func (d *FilterDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data filterDataSourceWithFilterModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
data := read[filterDataSourceWithFilterModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand Down
10 changes: 1 addition & 9 deletions opslevel/datasource_opslevel_filters_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,12 @@ func (d *FilterDataSourcesAll) Schema(ctx context.Context, req datasource.Schema
}

func (d *FilterDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel FilterDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}

filters, err := d.client.ListFilters(nil)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read filter, got error: %s", err))
return
}
stateModel = NewFilterDataSourcesAllModel(filters.Nodes)
stateModel := NewFilterDataSourcesAllModel(filters.Nodes)

// Save data into Terraform state
tflog.Trace(ctx, "listed all OpsLevel Filter data sources")
Expand Down
7 changes: 2 additions & 5 deletions opslevel/datasource_opslevel_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ func (i *IntegrationDataSource) Schema(ctx context.Context, req datasource.Schem
}

func (i *IntegrationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel integrationDataSourceWithFilterModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
planModel := read[integrationDataSourceWithFilterModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -87,7 +84,7 @@ func (i *IntegrationDataSource) Read(ctx context.Context, req datasource.ReadReq
return
}

stateModel = NewIntegrationDataSourceModel(ctx, *integration, planModel.Filter)
stateModel := NewIntegrationDataSourceModel(ctx, *integration, planModel.Filter)

// Save data into Terraform state
tflog.Trace(ctx, "read an OpsLevel Integration data source")
Expand Down
10 changes: 1 addition & 9 deletions opslevel/datasource_opslevel_integrations_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,14 @@ func (i *IntegrationDataSourcesAll) Schema(ctx context.Context, req datasource.S
}

func (i *IntegrationDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel integrationDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}

integrations, err := i.client.ListIntegrations(nil)
if err != nil || integrations == nil || integrations.Nodes == nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("unable to list integrations, got error: %s", err))
return
}

foundIntegrations := *integrations
stateModel = NewIntegrationDataSourcesAllModel(foundIntegrations.Nodes)
stateModel := NewIntegrationDataSourcesAllModel(foundIntegrations.Nodes)

// Save data into Terraform state
tflog.Trace(ctx, "listed all integrations data sources")
Expand Down
7 changes: 2 additions & 5 deletions opslevel/datasource_opslevel_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ func (lifecycleDataSource *LifecycleDataSource) Schema(ctx context.Context, req
}

func (lifecycleDataSource *LifecycleDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel lifecycleDataSourceWithFilterModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
planModel := read[lifecycleDataSourceWithFilterModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -100,7 +97,7 @@ func (lifecycleDataSource *LifecycleDataSource) Read(ctx context.Context, req da
return
}

stateModel = NewLifecycleDataSourceModel(ctx, *lifecycle, planModel.Filter)
stateModel := NewLifecycleDataSourceModel(ctx, *lifecycle, planModel.Filter)

// Save data into Terraform state
tflog.Trace(ctx, "read an OpsLevel Lifecycle data source")
Expand Down
10 changes: 1 addition & 9 deletions opslevel/datasource_opslevel_lifecycles_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,13 @@ func (d *LifecycleDataSourcesAll) Schema(ctx context.Context, req datasource.Sch
}

func (d *LifecycleDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel lifecycleDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}

lifecycles, err := d.client.ListLifecycles()
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("unable to list lifecycles, got error: %s", err))
return
}

stateModel = NewLifecycleDataSourcesAllModel(lifecycles)
stateModel := NewLifecycleDataSourcesAllModel(lifecycles)

// Save data into Terraform state
tflog.Trace(ctx, "listed all lifecycle data sources")
Expand Down
8 changes: 2 additions & 6 deletions opslevel/datasource_opslevel_property_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ func (d *PropertyDefinitionDataSource) Schema(ctx context.Context, req datasourc
}

func (d *PropertyDefinitionDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel propertyDefinitionDataSourceWithFilterModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)

planModel := read[propertyDefinitionDataSourceWithFilterModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -90,7 +86,7 @@ func (d *PropertyDefinitionDataSource) Read(ctx context.Context, req datasource.
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read property definition datasource, got error: %s", err))
return
}
stateModel = NewPropertyDefinitionDataSourceWithFilterModel(*propertydefinition, planModel.Identifier.ValueString())
stateModel := NewPropertyDefinitionDataSourceWithFilterModel(*propertydefinition, planModel.Identifier.ValueString())

// Save data into Terraform state
tflog.Trace(ctx, "read an OpsLevel PropertyDefinition data source")
Expand Down
11 changes: 1 addition & 10 deletions opslevel/datasource_opslevel_property_definitions_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,12 @@ func (d *PropertyDefinitionDataSourcesAll) Schema(ctx context.Context, req datas
}

func (d *PropertyDefinitionDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel propertyDefinitionDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)

if resp.Diagnostics.HasError() {
return
}

propertyDefinitions, err := d.client.ListPropertyDefinitions(nil)
if err != nil || propertyDefinitions == nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read property definition datasource, got error: %s", err))
return
}
stateModel = NewPropertyDefinitionDataSourcesAllModel(propertyDefinitions.Nodes)
stateModel := NewPropertyDefinitionDataSourcesAllModel(propertyDefinitions.Nodes)

// Save data into Terraform state
tflog.Trace(ctx, "read an OpsLevel PropertyDefinition data source")
Expand Down
7 changes: 2 additions & 5 deletions opslevel/datasource_opslevel_repositories_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ func (d *RepositoriesDataSourcesAll) Schema(ctx context.Context, req datasource.
}

func (d *RepositoriesDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel RepositoriesDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
planModel := read[RepositoriesDataSourcesAllModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -89,7 +86,7 @@ func (d *RepositoriesDataSourcesAll) Read(ctx context.Context, req datasource.Re
return
}

stateModel = NewRepositoriesDataSourcesAllModel(repos.Nodes)
stateModel := NewRepositoriesDataSourcesAllModel(repos.Nodes)
stateModel.Filter = planModel.Filter

// Save data into Terraform state
Expand Down
5 changes: 1 addition & 4 deletions opslevel/datasource_opslevel_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ func (d *RepositoryDataSource) Schema(ctx context.Context, req datasource.Schema
}

func (d *RepositoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data RepositoryDataSourceModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
data := read[RepositoryDataSourceModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand Down
10 changes: 1 addition & 9 deletions opslevel/datasource_opslevel_rubric_categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,12 @@ func (d *CategoryDataSourcesAll) Schema(ctx context.Context, req datasource.Sche
}

func (d *CategoryDataSourcesAll) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel CategoryDataSourcesAllModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}

categories, err := d.client.ListCategories(nil)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to list rubric_categories datasource, got error: %s", err))
return
}
stateModel = NewCategoryDataSourcesAllModel(categories.Nodes)
stateModel := NewCategoryDataSourcesAllModel(categories.Nodes)

// Save data into Terraform state
tflog.Trace(ctx, "listed all rubric_categories data sources")
Expand Down
10 changes: 3 additions & 7 deletions opslevel/datasource_opslevel_rubric_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ func (d *CategoryDataSource) Schema(ctx context.Context, req datasource.SchemaRe
}

func (d *CategoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var planModel, stateModel categoryDataSourceWithFilterModel

// Read Terraform configuration data into the model
resp.Diagnostics.Append(req.Config.Get(ctx, &planModel)...)

configModel := read[categoryDataSourceWithFilterModel](ctx, &resp.Diagnostics, req.Config)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -81,13 +77,13 @@ func (d *CategoryDataSource) Read(ctx context.Context, req datasource.ReadReques
return
}

category, err := filterRubricCategories(categories.Nodes, planModel.Filter)
category, err := filterRubricCategories(categories.Nodes, configModel.Filter)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to filter rubric_category datasource, got error: %s", err))
return
}

stateModel = NewCategoryDataSourceWithFilterModel(*category, planModel.Filter)
stateModel := NewCategoryDataSourceWithFilterModel(*category, configModel.Filter)

// Save data into Terraform state
tflog.Trace(ctx, "read an OpsLevel Rubric Category data source")
Expand Down
Loading

0 comments on commit 61a1c05

Please sign in to comment.