Skip to content

Commit

Permalink
Finish stream resource and data source dev
Browse files Browse the repository at this point in the history
  • Loading branch information
thogarty committed Jan 24, 2025
1 parent acbccd9 commit c4dfeea
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/fabric_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ subcategory: "Fabric"
Fabric V4 API compatible data resource that allow user to fetch Equinix Fabric Stream by UUID

Additional Documentation:
* Getting Started: TODO
* API: TODO
* Getting Started: https://docs.equinix.com/en-us/Content/KnowledgeCenter/Fabric/GettingStarted/Integrating-with-Fabric-V4-APIs/IntegrateWithSink.htm
* API: https://developer.equinix.com/catalog/fabricv4#tag/Streams

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/fabric_streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ subcategory: "Fabric"
Fabric V4 API compatible data resource that allow user to fetch Equinix Fabric Streams with pagination details

Additional Documentation:
* Getting Started: TODO
* API: TODO
* Getting Started: https://docs.equinix.com/en-us/Content/KnowledgeCenter/Fabric/GettingStarted/Integrating-with-Fabric-V4-APIs/IntegrateWithSink.htm
* API: https://developer.equinix.com/catalog/fabricv4#tag/Streams

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/fabric_stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ subcategory: "Fabric"
Fabric V4 API compatible resource allows creation and management of Equinix Fabric Stream

Additional Documentation:
* Getting Started: TODO
* API: TODO
* Getting Started: https://docs.equinix.com/en-us/Content/KnowledgeCenter/Fabric/GettingStarted/Integrating-with-Fabric-V4-APIs/IntegrateWithSink.htm
* API: https://developer.equinix.com/catalog/fabricv4#tag/Streams

## Example Usage

Expand Down
5 changes: 3 additions & 2 deletions internal/resources/fabric/stream/datasource_all_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package stream

import (
"context"

equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
"github.com/equinix/terraform-provider-equinix/internal/framework"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

func NewDataSourceAllStreams() datasource.DataSource {
Expand Down Expand Up @@ -57,7 +58,7 @@ func (r *DataSourceAllStreams) Read(ctx context.Context, request datasource.Read

if err != nil {
response.State.RemoveResource(ctx)
diag.FromErr(equinix_errors.FormatFabricError(err))
response.Diagnostics.AddError("api error retrieving streams data", equinix_errors.FormatFabricError(err).Error())
return
}

Expand Down
5 changes: 3 additions & 2 deletions internal/resources/fabric/stream/datasource_by_streamid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package stream

import (
"context"

equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
"github.com/equinix/terraform-provider-equinix/internal/framework"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

func NewDataSourceByStreamID() datasource.DataSource {
Expand Down Expand Up @@ -47,7 +48,7 @@ func (r *DataSourceByStreamID) Read(ctx context.Context, request datasource.Read

if err != nil {
response.State.RemoveResource(ctx)
diag.FromErr(equinix_errors.FormatFabricError(err))
response.Diagnostics.AddError("api error retrieving stream data", equinix_errors.FormatFabricError(err).Error())
return
}

Expand Down
10 changes: 6 additions & 4 deletions internal/resources/fabric/stream/datasources_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package stream

import (
"context"

"github.com/equinix/terraform-provider-equinix/internal/framework"
fwtypes "github.com/equinix/terraform-provider-equinix/internal/framework/types"

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

Expand All @@ -12,8 +14,8 @@ func dataSourceAllStreamsSchema(ctx context.Context) schema.Schema {
Description: `Fabric V4 API compatible data resource that allow user to fetch Equinix Fabric Streams with pagination details
Additional Documentation:
* Getting Started: TODO
* API: TODO`,
* Getting Started: https://docs.equinix.com/en-us/Content/KnowledgeCenter/Fabric/GettingStarted/Integrating-with-Fabric-V4-APIs/IntegrateWithSink.htm
* API: https://developer.equinix.com/catalog/fabricv4#tag/Streams`,
Attributes: map[string]schema.Attribute{
"id": framework.IDAttributeDefaultDescription(),
"pagination": schema.SingleNestedAttribute{
Expand Down Expand Up @@ -68,8 +70,8 @@ func dataSourceSingleStreamSchema(ctx context.Context) schema.Schema {
Description: `Fabric V4 API compatible data resource that allow user to fetch Equinix Fabric Stream by UUID
Additional Documentation:
* Getting Started: TODO
* API: TODO`,
* Getting Started: https://docs.equinix.com/en-us/Content/KnowledgeCenter/Fabric/GettingStarted/Integrating-with-Fabric-V4-APIs/IntegrateWithSink.htm
* API: https://developer.equinix.com/catalog/fabricv4#tag/Streams`,
Attributes: baseStreamSchema,
}
}
Expand Down
11 changes: 10 additions & 1 deletion internal/resources/fabric/stream/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package stream

import (
"context"
"github.com/equinix/equinix-sdk-go/services/fabricv4"

fwtypes "github.com/equinix/terraform-provider-equinix/internal/framework/types"

"github.com/equinix/equinix-sdk-go/services/fabricv4"

"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -95,6 +98,12 @@ func (m *DataSourceByIdModel) parse(ctx context.Context, stream *fabricv4.Stream
func (m *DataSourceAllStreamsModel) parse(ctx context.Context, streamsResponse *fabricv4.GetAllStreamResponse) diag.Diagnostics {
var diags diag.Diagnostics

if len(streamsResponse.GetData()) < 1 {
diags.AddError("no data retrieved by streams data source",
"either the account does not have any streams data to pull or the combination of limit and offset needs to be updated")
return diags
}

data := make([]BaseStreamModel, len(streamsResponse.GetData()))
streams := streamsResponse.GetData()
for index, stream := range streams {
Expand Down
6 changes: 4 additions & 2 deletions internal/resources/fabric/stream/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package stream
import (
"context"
"fmt"
equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
"net/http"
"slices"
"time"

"github.com/equinix/equinix-sdk-go/services/fabricv4"
equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
"github.com/equinix/terraform-provider-equinix/internal/framework"

"github.com/equinix/equinix-sdk-go/services/fabricv4"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
Expand Down
35 changes: 31 additions & 4 deletions internal/resources/fabric/stream/resource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ package stream

import (
"context"

"github.com/equinix/terraform-provider-equinix/internal/framework"
fwtypes "github.com/equinix/terraform-provider-equinix/internal/framework/types"

"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
)

func resourceSchema(ctx context.Context) schema.Schema {
return schema.Schema{
Description: `Fabric V4 API compatible resource allows creation and management of Equinix Fabric Stream
Additional Documentation:
* Getting Started: TODO
* API: TODO`,
* Getting Started: https://docs.equinix.com/en-us/Content/KnowledgeCenter/Fabric/GettingStarted/Integrating-with-Fabric-V4-APIs/IntegrateWithSink.htm
* API: https://developer.equinix.com/catalog/fabricv4#tag/Streams`,
Attributes: map[string]schema.Attribute{
"id": framework.IDAttributeDefaultDescription(),
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
Expand All @@ -39,7 +45,10 @@ Additional Documentation:
Description: "Equinix Project attribute object",
Optional: true,
Computed: true,
CustomType: fwtypes.NewObjectTypeOf[ProjectModel](ctx),
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
CustomType: fwtypes.NewObjectTypeOf[ProjectModel](ctx),
Attributes: map[string]schema.Attribute{
"project_id": schema.StringAttribute{
Description: "Equinix Subscriber-assigned project ID",
Expand All @@ -50,27 +59,45 @@ Additional Documentation:
"href": schema.StringAttribute{
Description: "Equinix auto generated URI to the stream resource in Equinix Portal",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"uuid": schema.StringAttribute{
Description: "Equinix-assigned unique id for the stream resource",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"state": schema.StringAttribute{
Description: "Value representing provisioning status for the stream resource",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"assets_count": schema.Int32Attribute{
Description: "Count of the streaming assets attached to the stream resource",
Computed: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknown(),
},
},
"stream_subscriptions_count": schema.Int32Attribute{
Description: "Count of the client subscriptions on the stream resource",
Computed: true,
PlanModifiers: []planmodifier.Int32{
int32planmodifier.UseStateForUnknown(),
},
},
"change_log": schema.SingleNestedAttribute{
Description: "Details of the last change on the stream resource",
Computed: true,
CustomType: fwtypes.NewObjectTypeOf[ChangeLogModel](ctx),
PlanModifiers: []planmodifier.Object{
objectplanmodifier.UseStateForUnknown(),
},
CustomType: fwtypes.NewObjectTypeOf[ChangeLogModel](ctx),
Attributes: map[string]schema.Attribute{
"created_by": schema.StringAttribute{
Description: "User name of creator of the stream resource",
Expand Down
3 changes: 2 additions & 1 deletion internal/resources/fabric/stream/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package stream_test
import (
"context"
"fmt"
"github.com/equinix/equinix-sdk-go/services/fabricv4"
"testing"

"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/equinix/terraform-provider-equinix/internal/config"

"github.com/equinix/equinix-sdk-go/services/fabricv4"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)
Expand Down

0 comments on commit c4dfeea

Please sign in to comment.