Skip to content

Commit

Permalink
feat: Fabric stream resource and data sources (#844)
Browse files Browse the repository at this point in the history
Using terraform-plugin-framework; added the following:
* equinix_fabric_stream resource
* equinix_fabric_stream data source
* equinix_fabric_streams data source

Included automated testing and docs creation leveraging description on
schemas

NOTE: Fixed usage of context within Fabric client creations and updated
all usages in SDKv2 as well
  • Loading branch information
thogarty authored Feb 3, 2025
1 parent bb3e055 commit fc4011e
Show file tree
Hide file tree
Showing 41 changed files with 1,617 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ linters:
- unused
issues:
max-issues-per-linter: 0
max-same-issues: 0
max-same-issues: 0
70 changes: 70 additions & 0 deletions docs/data-sources/fabric_stream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
subcategory: "Fabric"
---

# equinix_fabric_stream (Data Source)

Fabric V4 API compatible data resource that allow user to fetch Equinix Fabric Stream by UUID

Additional Documentation:
* 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

```terraform
data "equinix_fabric_stream" "data_stream" {
stream_id = "<uuid_of_stream>"
}
output "stream_state" {
value = data.equinix_fabric_stream.data_stream.state
}
```

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

### Required

- `stream_id` (String) The uuid of the stream this data source should retrieve

### Read-Only

- `assets_count` (Number) Count of the streaming assets attached to the stream resource
- `change_log` (Attributes) Details of the last change on the stream resource (see [below for nested schema](#nestedatt--change_log))
- `description` (String) Customer-provided description of the stream resource
- `href` (String) Equinix auto generated URI to the stream resource in Equinix Portal
- `id` (String) The unique identifier of the resource
- `name` (String) Customer-provided name of the stream resource
- `project` (Attributes) Equinix Project attribute object (see [below for nested schema](#nestedatt--project))
- `state` (String) Value representing provisioning status for the stream resource
- `stream_subscriptions_count` (Number) Count of the client subscriptions on the stream resource
- `type` (String) Equinix defined Streaming Type
- `uuid` (String) Equinix-assigned unique id for the stream resource

<a id="nestedatt--change_log"></a>
### Nested Schema for `change_log`

Read-Only:

- `created_by` (String) User name of creator of the stream resource
- `created_by_email` (String) Email of creator of the stream resource
- `created_by_full_name` (String) Legal name of creator of the stream resource
- `created_date_time` (String) Creation time of the stream resource
- `deleted_by` (String) User name of deleter of the stream resource
- `deleted_by_email` (String) Email of deleter of the stream resource
- `deleted_by_full_name` (String) Legal name of deleter of the stream resource
- `deleted_date_time` (String) Deletion time of the stream resource
- `updated_by` (String) User name of last updater of the stream resource
- `updated_by_email` (String) Email of last updater of the stream resource
- `updated_by_full_name` (String) Legal name of last updater of the stream resource
- `updated_date_time` (String) Last update time of the stream resource


<a id="nestedatt--project"></a>
### Nested Schema for `project`

Read-Only:

- `project_id` (String) Equinix Subscriber-assigned project ID
95 changes: 95 additions & 0 deletions docs/data-sources/fabric_streams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
subcategory: "Fabric"
---

# equinix_fabric_streams (Data Source)

Fabric V4 API compatible data resource that allow user to fetch Equinix Fabric Streams with pagination details

Additional Documentation:
* 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

```terraform
data "equinix_fabric_streams" "data_streams" {
pagination = {
limit = 2
offset = 1
}
}
output "number_of_returned_streams" {
value = length(data.equinix_fabric_streams.data_streams.data)
}
```

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

### Required

- `pagination` (Attributes) Pagination details for the returned streams list (see [below for nested schema](#nestedatt--pagination))

### Read-Only

- `data` (Attributes List) Returned list of stream objects (see [below for nested schema](#nestedatt--data))
- `id` (String) The unique identifier of the resource

<a id="nestedatt--pagination"></a>
### Nested Schema for `pagination`

Optional:

- `limit` (Number) Maximum number of search results returned per page. Number must be between 1 and 100, and the default is 20
- `offset` (Number) Index of the first item returned in the response. The default is 0

Read-Only:

- `next` (String) The URL relative to the next item in the response
- `previous` (String) The URL relative to the previous item in the response
- `total` (Number) The total number of streams available to the user making the request


<a id="nestedatt--data"></a>
### Nested Schema for `data`

Read-Only:

- `assets_count` (Number) Count of the streaming assets attached to the stream resource
- `change_log` (Attributes) Details of the last change on the stream resource (see [below for nested schema](#nestedatt--data--change_log))
- `description` (String) Customer-provided description of the stream resource
- `href` (String) Equinix auto generated URI to the stream resource in Equinix Portal
- `name` (String) Customer-provided name of the stream resource
- `project` (Attributes) Equinix Project attribute object (see [below for nested schema](#nestedatt--data--project))
- `state` (String) Value representing provisioning status for the stream resource
- `stream_subscriptions_count` (Number) Count of the client subscriptions on the stream resource
- `type` (String) Equinix defined Streaming Type
- `uuid` (String) Equinix-assigned unique id for the stream resource

<a id="nestedatt--data--change_log"></a>
### Nested Schema for `data.change_log`

Read-Only:

- `created_by` (String) User name of creator of the stream resource
- `created_by_email` (String) Email of creator of the stream resource
- `created_by_full_name` (String) Legal name of creator of the stream resource
- `created_date_time` (String) Creation time of the stream resource
- `deleted_by` (String) User name of deleter of the stream resource
- `deleted_by_email` (String) Email of deleter of the stream resource
- `deleted_by_full_name` (String) Legal name of deleter of the stream resource
- `deleted_date_time` (String) Deletion time of the stream resource
- `updated_by` (String) User name of last updater of the stream resource
- `updated_by_email` (String) Email of last updater of the stream resource
- `updated_by_full_name` (String) Legal name of last updater of the stream resource
- `updated_date_time` (String) Last update time of the stream resource


<a id="nestedatt--data--project"></a>
### Nested Schema for `data.project`

Read-Only:

- `project_id` (String) Equinix Subscriber-assigned project ID
89 changes: 89 additions & 0 deletions docs/resources/fabric_stream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
subcategory: "Fabric"
---

# equinix_fabric_stream (Resource)

Fabric V4 API compatible resource allows creation and management of Equinix Fabric Stream

Additional Documentation:
* 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

```terraform
resource "equinix_fabric_stream" "new_stream" {
type = "TELEMETRY_STREAM"
name = "<name_of_stream_resource>"
description = "<description_of_stream_resource>"
project = {
project_id = "<destination_project_id_for_stream"
}
}
output "stream_state" {
value = equinix_fabric_stream.new_stream.state
}
```

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

### Required

- `description` (String) Customer-provided description of the stream resource
- `name` (String) Customer-provided name of the stream resource
- `type` (String) Equinix defined Streaming Type

### Optional

- `project` (Attributes) Equinix Project attribute object (see [below for nested schema](#nestedatt--project))
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `assets_count` (Number) Count of the streaming assets attached to the stream resource
- `change_log` (Attributes) Details of the last change on the stream resource (see [below for nested schema](#nestedatt--change_log))
- `href` (String) Equinix auto generated URI to the stream resource in Equinix Portal
- `id` (String) The unique identifier of the resource
- `state` (String) Value representing provisioning status for the stream resource
- `stream_subscriptions_count` (Number) Count of the client subscriptions on the stream resource
- `uuid` (String) Equinix-assigned unique id for the stream resource

<a id="nestedatt--project"></a>
### Nested Schema for `project`

Required:

- `project_id` (String) Equinix Subscriber-assigned project ID


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).


<a id="nestedatt--change_log"></a>
### Nested Schema for `change_log`

Read-Only:

- `created_by` (String) User name of creator of the stream resource
- `created_by_email` (String) Email of creator of the stream resource
- `created_by_full_name` (String) Legal name of creator of the stream resource
- `created_date_time` (String) Creation time of the stream resource
- `deleted_by` (String) User name of deleter of the stream resource
- `deleted_by_email` (String) Email of deleter of the stream resource
- `deleted_by_full_name` (String) Legal name of deleter of the stream resource
- `deleted_date_time` (String) Deletion time of the stream resource
- `updated_by` (String) User name of last updater of the stream resource
- `updated_by_email` (String) Email of last updater of the stream resource
- `updated_by_full_name` (String) Legal name of last updater of the stream resource
- `updated_date_time` (String) Last update time of the stream resource
2 changes: 1 addition & 1 deletion equinix/data_source_fabric_cloud_routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func dataSourceFabricGetCloudRoutersRead(ctx context.Context, d *schema.Resource
}

func resourceFabricCloudRoutersSearch(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
cloudRouterSearchRequest := fabricv4.CloudRouterSearchRequest{}

schemaFilters := d.Get("filter").([]interface{})
Expand Down
14 changes: 7 additions & 7 deletions equinix/resource_fabric_cloud_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func marketplaceSubscriptionCloudRouterTerraformToGo(marketplaceSubscriptionTerr
return marketplaceSubscription
}
func resourceFabricCloudRouterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)

createCloudRouterRequest := fabricv4.CloudRouterPostRequest{}

Expand Down Expand Up @@ -329,7 +329,7 @@ func resourceFabricCloudRouterCreate(ctx context.Context, d *schema.ResourceData
}

func resourceFabricCloudRouterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
cloudRouter, _, err := client.CloudRoutersApi.GetCloudRouterByUuid(ctx, d.Id()).Execute()
if err != nil {
log.Printf("[WARN] Fabric Cloud Router %s not found , error %s", d.Id(), err)
Expand Down Expand Up @@ -465,7 +465,7 @@ func getCloudRouterUpdateRequests(cr *fabricv4.CloudRouter, d *schema.ResourceDa
}

func resourceFabricCloudRouterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
start := time.Now()
updateTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start)
dbCR, err := waitUntilCloudRouterIsProvisioned(d.Id(), meta, d, ctx, updateTimeout)
Expand Down Expand Up @@ -505,7 +505,7 @@ func waitForCloudRouterUpdateCompletion(uuid string, meta interface{}, d *schema
stateConf := &retry.StateChangeConf{
Target: []string{string(fabricv4.CLOUDROUTERACCESSPOINTSTATE_PROVISIONED)},
Refresh: func() (interface{}, string, error) {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
dbCR, _, err := client.CloudRoutersApi.GetCloudRouterByUuid(ctx, uuid).Execute()
if err != nil {
return "", "", equinix_errors.FormatFabricError(err)
Expand Down Expand Up @@ -536,7 +536,7 @@ func waitUntilCloudRouterIsProvisioned(uuid string, meta interface{}, d *schema.
string(fabricv4.CLOUDROUTERACCESSPOINTSTATE_PROVISIONED),
},
Refresh: func() (interface{}, string, error) {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
dbCR, _, err := client.CloudRoutersApi.GetCloudRouterByUuid(ctx, uuid).Execute()
if err != nil {
return "", "", equinix_errors.FormatFabricError(err)
Expand All @@ -559,7 +559,7 @@ func waitUntilCloudRouterIsProvisioned(uuid string, meta interface{}, d *schema.

func resourceFabricCloudRouterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
diags := diag.Diagnostics{}
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
start := time.Now()
_, err := client.CloudRoutersApi.DeleteCloudRouterByUuid(ctx, d.Id()).Execute()
if err != nil {
Expand Down Expand Up @@ -592,7 +592,7 @@ func WaitUntilCloudRouterDeprovisioned(uuid string, meta interface{}, d *schema.
string(fabricv4.CLOUDROUTERACCESSPOINTSTATE_DEPROVISIONED),
},
Refresh: func() (interface{}, string, error) {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
dbCR, _, err := client.CloudRoutersApi.GetCloudRouterByUuid(ctx, uuid).Execute()
if err != nil {
return "", "", equinix_errors.FormatFabricError(err)
Expand Down
4 changes: 2 additions & 2 deletions equinix/resource_fabric_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func portEncapsulationGoToTerraform(portEncapsulation *fabricv4.PortEncapsulatio
}

func resourceFabricPortRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
port, _, err := client.PortsApi.GetPortByUuid(ctx, d.Id()).Execute()
if err != nil {
log.Printf("[WARN] Port %s not found , error %s", d.Id(), err)
Expand Down Expand Up @@ -443,7 +443,7 @@ func resourceFabricPortGetByPortName(ctx context.Context, d *schema.ResourceData
}
}()

client := meta.(*config.Config).NewFabricClientForSDK(d)
client := meta.(*config.Config).NewFabricClientForSDK(ctx, d)
portNameParam := d.Get("filters").(*schema.Set).List()
portName := portName(portNameParam)
ports, _, err := client.PortsApi.GetPorts(ctx).Name(portName).Execute()
Expand Down
Loading

0 comments on commit fc4011e

Please sign in to comment.