Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway): onboard new resource/data-source #219

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
89b87ac
add gateway resource + datasource w/o tests
badeamarjieh Jan 26, 2025
c99ac71
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Jan 26, 2025
2053dcc
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Feb 2, 2025
5959a1c
1. support OnPremises and OnPremisesPersonal gateway types as data so…
badeamarjieh Feb 2, 2025
2d87bb6
add docs
badeamarjieh Feb 2, 2025
f7ce0e6
1. change get method from returning error to diag.Diagnostics
badeamarjieh Feb 2, 2025
577dab4
add unit tests phase 1
badeamarjieh Feb 11, 2025
c4714b2
add docs
badeamarjieh Feb 11, 2025
123b9d9
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Feb 11, 2025
36bd990
add unit tests and accept reference by id and display name for data s…
badeamarjieh Feb 12, 2025
944a727
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Feb 12, 2025
e556a7e
fix linting issues
badeamarjieh Feb 13, 2025
514a95b
Merge branch 'main' into support_polymorphic_gateway_datasource_and_r…
badeamarjieh Feb 13, 2025
2e6ab85
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Feb 13, 2025
cbdfc4f
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Feb 13, 2025
9784d7a
Merge branch 'support_polymorphic_gateway_datasource_and_resource' of…
badeamarjieh Feb 13, 2025
8e61321
remove onprem acc tests and from wellknown
badeamarjieh Feb 13, 2025
c544a10
fix well known ps script
badeamarjieh Feb 13, 2025
45079bb
fix lint and remove redundant code in Set-WellKno
badeamarjieh Feb 25, 2025
728c498
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Mar 6, 2025
545019b
update docs
badeamarjieh Mar 6, 2025
f1d729b
fix removal of graphql from merge fix
badeamarjieh Mar 6, 2025
5e278f5
add changelog and skip testacc for gateway role assignments CRUD for SPN
badeamarjieh Mar 7, 2025
715e469
Merge branch 'main' of https://github.com/microsoft/terraform-provide…
badeamarjieh Mar 7, 2025
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
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/microsoft/terraform-provider-fabric/internal/services/environment"
"github.com/microsoft/terraform-provider-fabric/internal/services/eventhouse"
"github.com/microsoft/terraform-provider-fabric/internal/services/eventstream"
"github.com/microsoft/terraform-provider-fabric/internal/services/gateway"
"github.com/microsoft/terraform-provider-fabric/internal/services/kqldatabase"
"github.com/microsoft/terraform-provider-fabric/internal/services/kqlqueryset"
"github.com/microsoft/terraform-provider-fabric/internal/services/lakehouse"
Expand Down Expand Up @@ -402,6 +403,7 @@ func (p *FabricProvider) DataSources(ctx context.Context) []func() datasource.Da
func() datasource.DataSource { return eventhouse.NewDataSourceEventhouses(ctx) },
eventstream.NewDataSourceEventstream,
eventstream.NewDataSourceEventstreams,
gateway.NewDataSourceGateway,
kqldatabase.NewDataSourceKQLDatabase,
kqldatabase.NewDataSourceKQLDatabases,
kqlqueryset.NewDataSourceKQLQueryset,
Expand Down
23 changes: 23 additions & 0 deletions internal/services/gateway/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MPL-2.0

package gateway

import (
"github.com/microsoft/terraform-provider-fabric/internal/common"
)

const (
ItemName = "Gateway"
ItemTFName = "gateway"
ItemsName = "Gateways"
ItemsTFName = "gateways"
ItemDocsSPNSupport = common.DocsSPNSupported
ItemDocsURL = "https://learn.microsoft.com/en-us/power-bi/guidance/powerbi-implementation-planning-data-gateways"
)

var (
PossibleInactivityMinutesBeforeSleepValues = []int32{30, 60, 90, 120, 150, 240, 360, 480, 720, 1440}

Check failure on line 20 in internal/services/gateway/base.go

View workflow job for this annotation

GitHub Actions / 🏗️ Check Build

PossibleInactivityMinutesBeforeSleepValues is a global variable (gochecknoglobals)
MinNumberOfMemberGatewaysValues = int32(1)

Check failure on line 21 in internal/services/gateway/base.go

View workflow job for this annotation

GitHub Actions / 🏗️ Check Build

MinNumberOfMemberGatewaysValues is a global variable (gochecknoglobals)
MaxNumberOfMemberGatewaysValues = int32(7)

Check failure on line 22 in internal/services/gateway/base.go

View workflow job for this annotation

GitHub Actions / 🏗️ Check Build

MaxNumberOfMemberGatewaysValues is a global variable (gochecknoglobals)
)
189 changes: 189 additions & 0 deletions internal/services/gateway/data_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MPL-2.0

package gateway

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework-timeouts/datasource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-log/tflog"
fabcore "github.com/microsoft/fabric-sdk-go/fabric/core"
supertypes "github.com/orange-cloudavenue/terraform-plugin-framework-supertypes"

"github.com/microsoft/terraform-provider-fabric/internal/common"
"github.com/microsoft/terraform-provider-fabric/internal/framework/customtypes"
"github.com/microsoft/terraform-provider-fabric/internal/pkg/utils"
pconfig "github.com/microsoft/terraform-provider-fabric/internal/provider/config"
)

var (
_ datasource.DataSourceWithConfigValidators = (*dataSourceGateway)(nil)
_ datasource.DataSourceWithConfigure = (*dataSourceGateway)(nil)
)

type dataSourceGateway struct {
pConfigData *pconfig.ProviderData
client *fabcore.GatewaysClient
}

func NewDataSourceGateway() datasource.DataSource {
return &dataSourceGateway{}
}

func (d *dataSourceGateway) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_" + ItemTFName
}

func (d *dataSourceGateway) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Get a Fabric " + ItemName + ".\n\n" +
"Use this data source to get [" + ItemName + "](" + ItemDocsURL + ").\n\n" +
ItemDocsSPNSupport,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The " + ItemName + " ID.",
Optional: true,
Computed: true,
CustomType: customtypes.UUIDType{},
},
"display_name": schema.StringAttribute{
MarkdownDescription: "The " + ItemName + " display name.",
Optional: true,
Computed: true,
},
"type": schema.StringAttribute{
MarkdownDescription: "The " + ItemName + " type. Possible values: " + utils.ConvertStringSlicesToString(fabcore.PossibleGatewayTypeValues(), true, true),
Computed: true,
},
"capacity_id": schema.StringAttribute{
MarkdownDescription: "The " + ItemName + " capacity ID.",
Computed: true,
CustomType: customtypes.UUIDType{},
},
"inactivity_minutes_before_sleep": schema.Int32Attribute{
MarkdownDescription: "The " + ItemName + " inactivity minutes before sleep. Possible values: " + utils.ConvertStringSlicesToString(PossibleInactivityMinutesBeforeSleepValues, true, true),
Computed: true,
},
"number_of_member_gateways": schema.Int32Attribute{
MarkdownDescription: "The number of member gateways. Possible values: " + fmt.Sprint(MinNumberOfMemberGatewaysValues) + " to " + fmt.Sprint(MaxNumberOfMemberGatewaysValues) + ".",
Computed: true,
},
"virtual_network_azure_resource": schema.SingleNestedAttribute{
MarkdownDescription: "The Azure virtual network resource.",
Computed: true,
CustomType: supertypes.NewSingleNestedObjectTypeOf[virtualNetworkAzureResourceModel](ctx),
Attributes: map[string]schema.Attribute{
"resource_group_name": schema.StringAttribute{
MarkdownDescription: "The resource group name.",
Computed: true,
},
"subnet_name": schema.StringAttribute{
MarkdownDescription: "The subnet name.",
Computed: true,
},
"subscription_id": schema.StringAttribute{
MarkdownDescription: "The subscription ID.",
Computed: true,
CustomType: customtypes.UUIDType{},
},
"virtual_network_name": schema.StringAttribute{
MarkdownDescription: "The virtual network name.",
Computed: true,
},
},
},
"timeouts": timeouts.Attributes(ctx),
},
}
}

func (d *dataSourceGateway) ConfigValidators(_ context.Context) []datasource.ConfigValidator {
return []datasource.ConfigValidator{
datasourcevalidator.Conflicting(
path.MatchRoot("id"),
path.MatchRoot("display_name"),
),
datasourcevalidator.ExactlyOneOf(
path.MatchRoot("id"),
path.MatchRoot("display_name"),
),
}
}

func (d *dataSourceGateway) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

pConfigData, ok := req.ProviderData.(*pconfig.ProviderData)
if !ok {
resp.Diagnostics.AddError(
common.ErrorDataSourceConfigType,
fmt.Sprintf(common.ErrorFabricClientType, req.ProviderData),
)

return
}

d.pConfigData = pConfigData
d.client = fabcore.NewClientFactoryWithClient(*pConfigData.FabricClient).NewGatewaysClient()
}

func (d *dataSourceGateway) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
tflog.Debug(ctx, "READ", map[string]any{
"action": "start",
})
tflog.Trace(ctx, "READ", map[string]any{
"config": req.Config,
})

var data dataSourceGatewayModel

if resp.Diagnostics.Append(req.Config.Get(ctx, &data)...); resp.Diagnostics.HasError() {
return
}

timeout, diags := data.Timeouts.Read(ctx, d.pConfigData.Timeout)
if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() {
return
}

ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

if resp.Diagnostics.Append(d.get(ctx, &data)...); resp.Diagnostics.HasError() {
return
}

resp.Diagnostics.Append(resp.State.Set(ctx, data)...)

tflog.Debug(ctx, "READ", map[string]any{
"action": "end",
})

if resp.Diagnostics.HasError() {
return
}
}

func (d *dataSourceGateway) get(ctx context.Context, model *dataSourceGatewayModel) diag.Diagnostics {
tflog.Trace(ctx, "GET "+ItemName+" BY ID", map[string]any{
"id": model.DisplayName.ValueString(),
})

respGet, err := d.client.GetGateway(ctx, model.ID.ValueString(), nil)
if diags := utils.GetDiagsFromError(ctx, err, utils.OperationRead, nil); diags.HasError() {
return diags
}

model.set(ctx, respGet.GatewayClassification)

return nil
}
Loading
Loading