Skip to content

Commit

Permalink
Merge pull request #4 from artie-labs/dana/datasource-cleanup
Browse files Browse the repository at this point in the history
Data source cleanup
  • Loading branch information
danafallon authored Jul 23, 2024
2 parents f552ad4 + cfc5f65 commit a8cf980
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 143 deletions.
24 changes: 0 additions & 24 deletions docs/data-sources/example.md

This file was deleted.

16 changes: 3 additions & 13 deletions internal/provider/deployments_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -39,21 +38,17 @@ type deploymentsResponse struct {
Deployments []deploymentsModel `json:"items"`
}

// deploymentsDataSource is the data source implementation.
type deploymentsDataSource struct {
endpoint string
apiKey string
}

// Metadata returns the data source type name.
func (d *deploymentsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_deployments"
}

// Configure adds the provider configured client to the data source.
func (d *deploymentsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}
Expand Down Expand Up @@ -94,7 +89,6 @@ func (d *deploymentsDataSource) Schema(_ context.Context, _ datasource.SchemaReq

// Read refreshes the Terraform state with the latest data.
func (d *deploymentsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
tflog.Info(ctx, fmt.Sprintf("Endpoint: %s", d.endpoint))
var state deploymentsDataSourceModel

apiReq, err := http.NewRequest("GET", fmt.Sprintf("%s/deployments", d.endpoint), nil)
Expand Down Expand Up @@ -139,10 +133,6 @@ func (d *deploymentsDataSource) Read(ctx context.Context, req datasource.ReadReq
state.Deployments = append(state.Deployments, deploymentState)
}

// Set state
diags := resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
105 changes: 0 additions & 105 deletions internal/provider/example_data_source.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (p *ArtieProvider) Resources(ctx context.Context) []func() resource.Resourc

func (p *ArtieProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewExampleDataSource,
NewDeploymentsDataSource,
}
}
Expand Down

0 comments on commit a8cf980

Please sign in to comment.