-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
492 additions
and
451 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
internal/provider/products_data_source.go → ...tasource/products/products_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package provider | ||
package products | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
internal/provider/datasource/service/service_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"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-log/tflog" | ||
|
||
tsClient "github.com/timescale/terraform-provider-timescale/internal/client" | ||
sc "github.com/timescale/terraform-provider-timescale/internal/schema" | ||
) | ||
|
||
// Ensure provider defined types fully satisfy framework interfaces. | ||
var _ datasource.DataSource = &ServiceDataSource{} | ||
var _ datasource.DataSourceWithConfigure = &ServiceDataSource{} | ||
|
||
func NewServiceDataSource() datasource.DataSource { | ||
return &ServiceDataSource{} | ||
} | ||
|
||
// ServiceDataSource defines the data source implementation. | ||
type ServiceDataSource struct { | ||
client *tsClient.Client | ||
} | ||
|
||
func (d *ServiceDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_service" | ||
} | ||
|
||
func (d *ServiceDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
// This description is used by the documentation generator and the language server. | ||
MarkdownDescription: "Service data source", | ||
Attributes: sc.Converter(sc.Service()), | ||
} | ||
} | ||
|
||
func (d *ServiceDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
tflog.Trace(ctx, "ServiceDataSource.Configure") | ||
|
||
if req.ProviderData == nil { | ||
return | ||
} | ||
client, ok := req.ProviderData.(*tsClient.Client) | ||
|
||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Client Type", | ||
fmt.Sprintf("Expected *tsClient.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
return | ||
} | ||
|
||
d.client = client | ||
} | ||
|
||
func (d *ServiceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
tflog.Trace(ctx, "ServiceDataSource.Read") | ||
|
||
var id string | ||
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("id"), &id)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
tflog.Error(ctx, fmt.Sprintf("error reading terraform plan %v", resp.Diagnostics.Errors())) | ||
return | ||
} | ||
|
||
tflog.Info(ctx, "Getting Service: "+id) | ||
service, err := d.client.GetService(ctx, id) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read service, got error: %s", err)) | ||
return | ||
} | ||
state := sc.NewService(ctx, service, &resp.Diagnostics, nil) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, state)...) | ||
if resp.Diagnostics.HasError() { | ||
tflog.Error(ctx, fmt.Sprintf("error updating terraform state %v", resp.Diagnostics.Errors())) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.