diff --git a/docs/data-sources/fabric_stream.md b/docs/data-sources/fabric_stream.md index cdc965c74..627b5adad 100644 --- a/docs/data-sources/fabric_stream.md +++ b/docs/data-sources/fabric_stream.md @@ -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 diff --git a/docs/data-sources/fabric_streams.md b/docs/data-sources/fabric_streams.md index 9166fd51a..744e8be29 100644 --- a/docs/data-sources/fabric_streams.md +++ b/docs/data-sources/fabric_streams.md @@ -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 diff --git a/docs/resources/fabric_stream.md b/docs/resources/fabric_stream.md index a8d0f96a2..4fcf9bf7a 100644 --- a/docs/resources/fabric_stream.md +++ b/docs/resources/fabric_stream.md @@ -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 diff --git a/internal/resources/fabric/stream/datasource_all_streams.go b/internal/resources/fabric/stream/datasource_all_streams.go index 9c9deaf08..08c689111 100644 --- a/internal/resources/fabric/stream/datasource_all_streams.go +++ b/internal/resources/fabric/stream/datasource_all_streams.go @@ -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 { @@ -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 } diff --git a/internal/resources/fabric/stream/datasource_by_streamid.go b/internal/resources/fabric/stream/datasource_by_streamid.go index 508db8a05..1e4a09c64 100644 --- a/internal/resources/fabric/stream/datasource_by_streamid.go +++ b/internal/resources/fabric/stream/datasource_by_streamid.go @@ -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 { @@ -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 } diff --git a/internal/resources/fabric/stream/datasources_schema.go b/internal/resources/fabric/stream/datasources_schema.go index b4323b4fa..9362a0522 100644 --- a/internal/resources/fabric/stream/datasources_schema.go +++ b/internal/resources/fabric/stream/datasources_schema.go @@ -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" ) @@ -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{ @@ -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, } } diff --git a/internal/resources/fabric/stream/models.go b/internal/resources/fabric/stream/models.go index fa42b74ae..d754d74e8 100644 --- a/internal/resources/fabric/stream/models.go +++ b/internal/resources/fabric/stream/models.go @@ -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" @@ -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 { diff --git a/internal/resources/fabric/stream/resource.go b/internal/resources/fabric/stream/resource.go index e08af5001..f2133931b 100644 --- a/internal/resources/fabric/stream/resource.go +++ b/internal/resources/fabric/stream/resource.go @@ -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" diff --git a/internal/resources/fabric/stream/resource_schema.go b/internal/resources/fabric/stream/resource_schema.go index 3d1e1ec25..5e5018886 100644 --- a/internal/resources/fabric/stream/resource_schema.go +++ b/internal/resources/fabric/stream/resource_schema.go @@ -2,10 +2,16 @@ 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 { @@ -13,8 +19,8 @@ func resourceSchema(ctx context.Context) 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{ @@ -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", @@ -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", diff --git a/internal/resources/fabric/stream/resource_test.go b/internal/resources/fabric/stream/resource_test.go index 9208ac431..7dbf3cc8a 100644 --- a/internal/resources/fabric/stream/resource_test.go +++ b/internal/resources/fabric/stream/resource_test.go @@ -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" )