Files
terraform-provider-fabric/internal/services/eventstreamdestinationconnection/models.go
T
Badea MarjiehandCopilot 3324e92aa6 build(deps): bump fabric-sdk-go to v0.21.0 (#1124)
# 📥 Pull Request

## ❓ What are you trying to address

`github.com/microsoft/fabric-sdk-go` v0.21.0 introduces breaking
changes, so the provider no longer compiles or passes unit tests after
the bump from v0.20.0. This PR does the bump and restores compatibility.
It changes no Terraform schemas and adds no features.

There is no linked issue. The failures were found while updating the
SDK:

- **Build failure:** `fabeventstream.SourceConnectionResponse` /
`DestinationConnectionResponse` no longer exist. The
`TopologyClientGetEventstream{Source,Destination}ConnectionResponse`
types now embed the polymorphic `EndpointConnectionClassification`.
- **Unit-test failure:** `fabric.NewClient` now writes the resolved
cloud configuration back into the caller's `ClientOptions`. It also
requires any non-empty `Cloud` to contain a `"microsoftFabric"` service
entry. The unit-test provider factory reused one options pointer, so
every client creation after the first failed with `cloud configuration
has no "microsoftFabric" service`.

## ✨ Description of new changes

**Dependencies**

- Bumped `github.com/microsoft/fabric-sdk-go` v0.20.0 → v0.21.0 via `go
get` + `go mod tidy`.
- The other bumps are only the minimum versions v0.21.0 requires:
`azcore` v1.23.2, `azidentity` v1.14.1, MSAL v1.8.0, `testify` v1.12.1,
`go.yaml.in/yaml/v3` v3.0.5.
- Tidy also dropped indirect modules that `testify` v1.12.1 no longer
needs.

**Eventstream source/destination connection (data sources + ephemeral
resources)**

- Follows the repo's polymorphic pattern, as in `gateway` /
`connection`. `set()` in `eventstreamsourceconnection/models.go` and
`eventstreamdestinationconnection/models.go` now takes
`fabeventstream.EndpointConnectionClassification` and type-switches on
it.
- The existing Event Hub fields (`event_hub_name`,
`fully_qualified_namespace`, `consumer_group_name`, `access_keys`) are
mapped from `*CustomEndpointConnection`, so current behaviour is
unchanged.
- Any other endpoint type (e.g. Kafka), the base `EndpointConnection`,
or `nil` now returns an explicit `Unsupported Eventstream
source/destination connection type` diagnostic instead of being silently
mis-mapped.
- **Known limitation:** Kafka endpoints are not supported. Supporting
them would be a separate feature.

**Unit-test helper (`internal/testhelp/testunit.go`)**

- The test provider factory now copies the `fabric.ClientOptions` for
each client creation, because the SDK mutates them.
- Production client creation (`createDefaultClient`) already builds
fresh options on each call and is unaffected.
- This SDK behaviour differs from `azcore`, which treats caller options
as read-only, and could be reported upstream.

**Tests**

- The inline fakes now return `*fabeventstream.CustomEndpointConnection`
wrapped in the new response types.
- Added `TestUnit_EventstreamSourceConnectionDataSource_EndpointTypes`
and `TestUnit_EventstreamDestinationConnectionDataSource_EndpointTypes`.
They cover:
  - a custom endpoint without access keys (`access_keys` stays null)
  - a Kafka endpoint (error)
  - an unknown base endpoint (error)
  - a `nil` endpoint (error)

**Validation**

All runs below are on this branch (based on `main` @ `150412ce`, Go
1.27.1) unless noted otherwise.

| Command | Result |
| --- | --- |
| `go vet ./...` (all packages incl. tests) | ✅ passed |
| `task testunit -- Eventstream ./internal/services/eventstream...` | ✅
passed: 20 tests (coverage: `eventstream` 100%,
`eventstreamsourceconnection` 87.9%, `eventstreamdestinationconnection`
88.1%) |
| `task testunit -- Provider ./internal/provider` | ✅ passed: 9 tests
(covers the `testunit.go` change) |
| `golangci-lint run ./internal/services/eventstreamsourceconnection/...
./internal/services/eventstreamdestinationconnection/...
./internal/testhelp/...` (v2.15.0) | ✅ 0 issues |
| `task testacc -- Eventstream ./internal/services/eventstream...` (run
before rebasing onto latest `main`, same fix + SDK v0.21.0; not re-run
after rebase) | ⚠️ 6/9 passed, 3 failed (unrelated, see below) |

The acceptance tests ran against a live tenant:

- The source and destination connection data source and ephemeral
resource tests **passed** against the real API.
- `TestAcc_EventstreamResource_CRUD`,
`TestAcc_EventstreamDefinitionResource_CRUD` and
`TestAcc_EventstreamDefinitionResource_CRUD_Parameters` **failed before
any Eventstream code ran**. Creating their prerequisite folder or
Lakehouse returned `404 EntityNotFound` because the local well-known
`WorkspaceRS` workspace had been deleted, which a direct API check
confirmed. This is a stale local fixture, not a regression from this
change.

**Changelog:** no entry is included; this is a dependency bump plus
compatibility fixes, and the PR is labelled `skip-changelog`.

## ☑️ PR Checklist

- [ ] Link to the issue you are addressing is included above <!-- No
issue exists; context is described above. -->
- [x] Ensure the PR description clearly describes the feature you're
adding and any known limitations

## ☑️ Resources / Data Sources Checklist

PRs for new/enhanced resources or data sources are expected to meet the
following criteria:

- [x] Production quality implementation of the resource or data-source
in [./internal/services](./internal/services)
- [x] Unit Tests and Acceptance Tests for your contribution in
[./internal/services/<service_name>](./internal/services)
  - [x] Tests should pass and provide >80% coverage of your contribution
- [ ] Examples for your contribution in [./examples](./examples) (see
[Terraform Documentation on
examples](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-documentation-generation#add-configuration-examples))
<!-- N/A: no schema or usage change. -->
- [ ] [Schema
descriptions](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-documentation-generation#add-schema-descriptions)
for your resource or data-source in
[./internal/services](./internal/services) <!-- N/A: no schema change.
-->
- [ ] Docs templates in [./templates](./templates) <!-- N/A: no docs
change. -->
- [ ] Updated auto-generated documentation in [./docs](./docs). (DO NOT
manually edit [./docs](./docs) - your updates will be overwritten) <!--
N/A: no schema change, so generated docs are unchanged. -->

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-20 09:58:57 +03:00

92 lines
3.7 KiB
Go

// Copyright Microsoft Corporation 2026
// SPDX-License-Identifier: MPL-2.0
package eventstreamdestinationconnection
import (
"context"
"fmt"
timeoutsD "github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts" //revive:disable-line:import-alias-naming
timeoutsE "github.com/hashicorp/terraform-plugin-framework-timeouts/ephemeral/timeouts" //revive:disable-line:import-alias-naming
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
fabeventstream "github.com/microsoft/fabric-sdk-go/fabric/eventstream"
supertypes "github.com/orange-cloudavenue/terraform-plugin-framework-supertypes"
"github.com/microsoft/terraform-provider-fabric/internal/framework/customtypes"
)
type dataSourceEventstreamDestinationConnectionModel struct {
baseEventstreamDestinationConnectionModel
Timeouts timeoutsD.Value `tfsdk:"timeouts"`
}
type ephemeralEventstreamDestinationConnectionModel struct {
baseEventstreamDestinationConnectionModel
Timeouts timeoutsE.Value `tfsdk:"timeouts"`
}
type baseEventstreamDestinationConnectionModel struct {
DestinationID customtypes.UUID `tfsdk:"destination_id"`
EventstreamID customtypes.UUID `tfsdk:"eventstream_id"`
WorkspaceID customtypes.UUID `tfsdk:"workspace_id"`
EventHubName types.String `tfsdk:"event_hub_name"`
FullyQualifiedNamespace types.String `tfsdk:"fully_qualified_namespace"`
ConsumerGroupName types.String `tfsdk:"consumer_group_name"`
AccessKeys supertypes.SingleNestedObjectValueOf[accessKeysModel] `tfsdk:"access_keys"`
}
func (to *baseEventstreamDestinationConnectionModel) set(ctx context.Context, workspaceID, eventstreamID, destinationID string, from fabeventstream.EndpointConnectionClassification) diag.Diagnostics {
to.DestinationID = customtypes.NewUUIDValue(destinationID)
to.EventstreamID = customtypes.NewUUIDValue(eventstreamID)
to.WorkspaceID = customtypes.NewUUIDValue(workspaceID)
accessKeys := supertypes.NewSingleNestedObjectValueOfNull[accessKeysModel](ctx)
switch entity := from.(type) {
case *fabeventstream.CustomEndpointConnection:
to.EventHubName = types.StringPointerValue(entity.EventHubName)
to.FullyQualifiedNamespace = types.StringPointerValue(entity.FullyQualifiedNamespace)
to.ConsumerGroupName = types.StringPointerValue(entity.ConsumerGroupName)
if entity.AccessKeys != nil {
accessKeysModel := &accessKeysModel{}
accessKeysModel.set(*entity.AccessKeys)
if diags := accessKeys.Set(ctx, accessKeysModel); diags.HasError() {
return diags
}
}
default:
var diags diag.Diagnostics
diags.AddError(
"Unsupported Eventstream destination connection type",
fmt.Sprintf("The Eventstream destination connection type '%T' is not supported.", entity),
)
return diags
}
to.AccessKeys = accessKeys
return nil
}
type accessKeysModel struct {
PrimaryKey types.String `tfsdk:"primary_key"`
SecondaryKey types.String `tfsdk:"secondary_key"`
PrimaryConnectionString types.String `tfsdk:"primary_connection_string"`
SecondaryConnectionString types.String `tfsdk:"secondary_connection_string"`
}
func (to *accessKeysModel) set(from fabeventstream.AccessKeys) {
to.PrimaryKey = types.StringPointerValue(from.PrimaryKey)
to.SecondaryKey = types.StringPointerValue(from.SecondaryKey)
to.PrimaryConnectionString = types.StringPointerValue(from.PrimaryConnectionString)
to.SecondaryConnectionString = types.StringPointerValue(from.SecondaryConnectionString)
}