Skip to content

Commit

Permalink
Merge pull request #872 from Juniper/871-add-version-checking-to-disa…
Browse files Browse the repository at this point in the history
…ble-data-source-apstra_blueprint_iba_dashboards

Disable resource apstra_blueprint_iba_dashboards with 5.x.x
  • Loading branch information
chrismarget-j authored Sep 25, 2024
2 parents f6faf67 + 024f5ba commit f244487
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
20 changes: 6 additions & 14 deletions apstra/data_source_blueprint_iba_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,8 @@ func (o *dataSourceBlueprintIbaDashboard) Schema(_ context.Context, _ datasource
}
}

func (o *dataSourceBlueprintIbaDashboard) ValidateConfig(ctx context.Context, req datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) {
// Retrieve values from config.
var config iba.Dashboard
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}

// cannot proceed to config + api version validation if the provider has not been configured
func (o *dataSourceBlueprintIbaDashboard) ValidateConfig(_ context.Context, _ datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) {
// cannot proceed to api version validation if the provider has not been configured
if o.client == nil {
return
}
Expand All @@ -62,7 +55,6 @@ func (o *dataSourceBlueprintIbaDashboard) ValidateConfig(ctx context.Context, re
"Incompatible API version",
"This data source is compatible only with Apstra "+compatibility.BpIbaDashboardOk.String(),
)
return
}
}

Expand Down Expand Up @@ -127,11 +119,11 @@ func (o *dataSourceBlueprintIbaDashboard) Read(ctx context.Context, req datasour
resp.Diagnostics.Append(resp.State.Set(ctx, &config)...)
}

func (o *dataSourceBlueprintIbaDashboard) setBpClientFunc(f func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)) {
o.getBpClientFunc = f
}

// setClient is used for API version compatibility check only
func (o *dataSourceBlueprintIbaDashboard) setClient(client *apstra.Client) {
o.client = client
}

func (o *dataSourceBlueprintIbaDashboard) setBpClientFunc(f func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)) {
o.getBpClientFunc = f
}
32 changes: 30 additions & 2 deletions apstra/data_source_blueprint_iba_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package tfapstra
import (
"context"
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/compatibility"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand All @@ -13,11 +16,16 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

var _ datasource.DataSourceWithConfigure = &dataSourceBlueprintIbaDashboards{}
var _ datasourceWithSetDcBpClientFunc = &dataSourceBlueprintIbaDashboards{}
var (
_ datasource.DataSourceWithConfigure = &dataSourceBlueprintIbaDashboards{}
_ datasource.DataSourceWithValidateConfig = &dataSourceBlueprintIbaDashboards{}
_ datasourceWithSetDcBpClientFunc = &dataSourceBlueprintIbaDashboards{}
_ datasourceWithSetClient = &dataSourceBlueprintIbaDashboards{}
)

type dataSourceBlueprintIbaDashboards struct {
getBpClientFunc func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)
client *apstra.Client
}

func (o *dataSourceBlueprintIbaDashboards) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand Down Expand Up @@ -47,6 +55,21 @@ func (o *dataSourceBlueprintIbaDashboards) Schema(_ context.Context, _ datasourc
}
}

func (o *dataSourceBlueprintIbaDashboards) ValidateConfig(_ context.Context, _ datasource.ValidateConfigRequest, resp *datasource.ValidateConfigResponse) {
// cannot proceed to config + api version validation if the provider has not been configured
if o.client == nil {
return
}

// only supported with Apstra 4.x
if !compatibility.BpIbaDashboardOk.Check(version.Must(version.NewVersion(o.client.ApiVersion()))) {
resp.Diagnostics.AddError(
"Incompatible API version",
"This data source is compatible only with Apstra "+compatibility.BpIbaDashboardOk.String(),
)
}
}

func (o *dataSourceBlueprintIbaDashboards) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config struct {
BlueprintId types.String `tfsdk:"blueprint_id"`
Expand Down Expand Up @@ -98,3 +121,8 @@ func (o *dataSourceBlueprintIbaDashboards) Read(ctx context.Context, req datasou
func (o *dataSourceBlueprintIbaDashboards) setBpClientFunc(f func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)) {
o.getBpClientFunc = f
}

// setClient is used for API version compatibility check only
func (o *dataSourceBlueprintIbaDashboards) setClient(client *apstra.Client) {
o.client = client
}

0 comments on commit f244487

Please sign in to comment.