Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ provider_installation {
* [airbyte_source_zoom](docs/data-sources/source_zoom.md)
* [airbyte_source_definition](docs/data-sources/source_definition.md)
* [airbyte_workspace](docs/data-sources/workspace.md)
* [airbyte_workspace_ids](docs/data-sources/workspace_ids.md)
<!-- End Available Resources and Data Sources [operations] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->
Expand Down
31 changes: 31 additions & 0 deletions docs/data-sources/workspace_ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "airbyte_workspace_ids Data Source - terraform-provider-airbyte"
subcategory: ""
description: |-
Get all Airbyte Workspace IDs (first will always be the default one created by Airbyte on launch)
---

# airbyte_workspace_ids (Data Source)

Get all Airbyte Workspace IDs (first will always be the default one created by Airbyte on launch)

## Example Usage

```terraform
data "airbyte_workspace_ids" "all" {}

resource "airbyte_source_faker" "test" {
# First workspace returned will be the default created by Airbyte when bootstrapped
workspace_id = data.airbyte_workspace_ids.all.ids[0]
# ...
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (String) The ID of this resource.
- `ids` (List of String) Workspace ID List
8 changes: 8 additions & 0 deletions examples/data-sources/airbyte_workspace_ids/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "airbyte_workspace_ids" "all" {}

resource "airbyte_source_faker" "test" {
# First workspace returned will be the default created by Airbyte when bootstrapped
workspace_id = data.airbyte_workspace_ids.all.ids[0]
# ...
}

1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ func (p *AirbyteProvider) DataSources(ctx context.Context) []func() datasource.D
NewSourceZoomDataSource,
NewSourceDefinitionDataSource,
NewWorkspaceDataSource,
NewWorkspaceIdsDataSource,
}
}

Expand Down
123 changes: 123 additions & 0 deletions internal/provider/workspace_ids_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// workspace_ids_data_source.go

package provider

import (
"context"
"fmt"
"strconv"
"time"

"github.com/airbytehq/terraform-provider-airbyte/internal/sdk"
"github.com/airbytehq/terraform-provider-airbyte/internal/sdk/models/operations"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSource = &WorkspaceIdsDataSource{}
var _ datasource.DataSourceWithConfigure = &WorkspaceIdsDataSource{}

func NewWorkspaceIdsDataSource() datasource.DataSource {
return &WorkspaceIdsDataSource{}
}

// WorkspaceIdsDataSource defines the data source implementation.
type WorkspaceIdsDataSource struct {
client *sdk.SDK
}

// WorkspaceIdsDataSourceModel describes the data model.
type WorkspaceIdsDataSourceModel struct {
Id types.String `tfsdk:"id"`
Ids types.List `tfsdk:"ids"`
}

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

// Schema defines the schema for the data source.
func (d *WorkspaceIdsDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Get all Airbyte Workspace IDs (first will always be the default one created by Airbyte on launch)",

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"ids": schema.ListAttribute{
Description: "Workspace ID List",
ElementType: types.StringType,
Computed: true,
},
},
}
}

// Configure adds the provider configured client to the data source.
func (d *WorkspaceIdsDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
return
}

client, ok := req.ProviderData.(*sdk.SDK)

if !ok {
resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type",
fmt.Sprintf("Expected *sdk.SDK, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

d.client = client
}

// Read refreshes the Terraform state with the latest data.
func (d *WorkspaceIdsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config WorkspaceIdsDataSourceModel

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

if resp.Diagnostics.HasError() {
return
}

// Call the new ListWorkspaces API endpoint
request := operations.ListWorkspacesRequest{}

response, err := d.client.Workspaces.ListWorkspaces(ctx, request)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read workspaces, got error: %s", err))
return
}

// Extract workspace IDs from the response
var workspaceIds []attr.Value
if response.WorkspacesResponse != nil {
for _, workspace := range response.WorkspacesResponse.GetData() {
workspaceIds = append(workspaceIds, types.StringValue(workspace.GetWorkspaceID()))
}
}

ids, diags := types.ListValue(types.StringType, workspaceIds)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

state := WorkspaceIdsDataSourceModel{
Id: types.StringValue(strconv.FormatInt(time.Now().Unix(), 10)),
Ids: ids,
}

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
Loading