Skip to content

Commit

Permalink
Merge pull request #880 from Juniper/879-remove-iba-probe-from-provid…
Browse files Browse the repository at this point in the history
…er-pending-update-for-5x-api

Disable IBA Probe with 5.x
  • Loading branch information
chrismarget-j authored Sep 26, 2024
2 parents b153d87 + 39653bb commit 3730466
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 13 deletions.
5 changes: 4 additions & 1 deletion apstra/compatibility/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ import (
"github.com/chrismarget-j/version-constraints"
)

var BpIbaDashboardOk = versionconstraints.New(apiversions.LtApstra500)
var (
BpIbaDashboardOk = versionconstraints.New(apiversions.LtApstra500)
BpIbaProbeOk = versionconstraints.New(apiversions.LtApstra500)
)
3 changes: 2 additions & 1 deletion apstra/data_source_blueprint_iba_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func (o *dataSourceBlueprintIbaDashboard) Schema(_ context.Context, _ datasource
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryRefDesignAny + "This data source provides details of a specific IBA Dashboard in a Blueprint." +
"\n\n" +
"At least one optional attribute is required.",
"At least one optional attribute is required.\n\n" +
"*Note: Compatible only with Apstra " + compatibility.BpIbaDashboardOk.String() + "*",
Attributes: iba.Dashboard{}.DataSourceAttributes(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion apstra/data_source_blueprint_iba_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func (o *dataSourceBlueprintIbaDashboards) Configure(ctx context.Context, req da

func (o *dataSourceBlueprintIbaDashboards) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryRefDesignAny + "This data source returns the ID numbers of all IBA Dashboards in a Blueprint.",
MarkdownDescription: docCategoryRefDesignAny + "This data source returns the ID numbers of all IBA Dashboards in a Blueprint.\n\n" +
"*Note: Compatible only with Apstra " + compatibility.BpIbaDashboardOk.String() + "*",
Attributes: map[string]schema.Attribute{
"blueprint_id": schema.StringAttribute{
MarkdownDescription: "Apstra Blueprint ID. " +
Expand Down
13 changes: 9 additions & 4 deletions apstra/data_source_blueprint_iba_predefined_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ 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/iba"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
)

var _ datasource.DataSourceWithConfigure = &dataSourceBlueprintIbaPredefinedProbe{}
var _ datasourceWithSetDcBpClientFunc = &dataSourceBlueprintIbaPredefinedProbe{}
var (
_ datasource.DataSourceWithConfigure = &dataSourceBlueprintIbaPredefinedProbe{}
_ datasourceWithSetDcBpClientFunc = &dataSourceBlueprintIbaPredefinedProbe{}
)

type dataSourceBlueprintIbaPredefinedProbe struct {
getBpClientFunc func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)
Expand All @@ -28,8 +32,9 @@ func (o *dataSourceBlueprintIbaPredefinedProbe) Configure(ctx context.Context, r

func (o *dataSourceBlueprintIbaPredefinedProbe) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryRefDesignAny + "This data source provides details of a specific IBA Predefined Probe in a Blueprint.",
Attributes: iba.PredefinedProbe{}.DataSourceAttributes(),
MarkdownDescription: docCategoryRefDesignAny + "This data source provides details of a specific IBA Predefined Probe in a Blueprint.\n\n" +
"*Note: Compatible only with Apstra " + compatibility.BpIbaProbeOk.String() + "*",
Attributes: iba.PredefinedProbe{}.DataSourceAttributes(),
}
}

Expand Down
5 changes: 3 additions & 2 deletions apstra/resource_blueprint_iba_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func (o *resourceBlueprintIbaDashboard) Configure(ctx context.Context, req resou

func (o *resourceBlueprintIbaDashboard) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryRefDesignAny + "This resource creates a IBA Dashboard.",
Attributes: iba.Dashboard{}.ResourceAttributes(),
MarkdownDescription: docCategoryRefDesignAny + "This resource creates a IBA Dashboard.\n\n" +
"*Note: Compatible only with Apstra " + compatibility.BpIbaDashboardOk.String() + "*",
Attributes: iba.Dashboard{}.ResourceAttributes(),
}
}

Expand Down
32 changes: 30 additions & 2 deletions apstra/resource_blueprint_iba_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ 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/iba"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
)

var _ resource.ResourceWithConfigure = &resourceBlueprintIbaProbe{}
var _ resourceWithSetDcBpClientFunc = &resourceBlueprintIbaProbe{}
var (
_ resource.ResourceWithConfigure = &resourceBlueprintIbaProbe{}
_ resource.ResourceWithValidateConfig = &resourceBlueprintIbaProbe{}
_ resourceWithSetDcBpClientFunc = &resourceBlueprintIbaProbe{}
_ resourceWithSetClient = &resourceBlueprintIbaProbe{}
)

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

func (o *resourceBlueprintIbaProbe) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
Expand All @@ -32,6 +40,21 @@ func (o *resourceBlueprintIbaProbe) Schema(_ context.Context, _ resource.SchemaR
}
}

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

// only supported with Apstra 4.x
if !compatibility.BpIbaProbeOk.Check(version.Must(version.NewVersion(o.client.ApiVersion()))) {
resp.Diagnostics.AddError(
"Incompatible API version",
"*Note: Compatible only with Apstra "+compatibility.BpIbaProbeOk.String()+"*",
)
}
}

func (o *resourceBlueprintIbaProbe) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Retrieve values from plan
var plan iba.Probe
Expand Down Expand Up @@ -169,3 +192,8 @@ func (o *resourceBlueprintIbaProbe) Delete(ctx context.Context, req resource.Del
func (o *resourceBlueprintIbaProbe) setBpClientFunc(f func(context.Context, string) (*apstra.TwoStageL3ClosClient, error)) {
o.getBpClientFunc = f
}

// setClient is used for API version compatibility check only
func (o *resourceBlueprintIbaProbe) setClient(client *apstra.Client) {
o.client = client
}
14 changes: 12 additions & 2 deletions apstra/resource_blueprint_iba_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package tfapstra
import (
"context"
"fmt"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"regexp"
"testing"

"github.com/Juniper/terraform-provider-apstra/apstra/compatibility"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const (
Expand Down Expand Up @@ -166,6 +169,13 @@ resource "apstra_blueprint_iba_probe" "p_device_health" {

func TestAccResourceProbe(t *testing.T) {
ctx := context.Background()

client := testutils.GetTestClient(t, ctx)
clientVersion := version.Must(version.NewVersion(client.ApiVersion()))
if !compatibility.BpIbaProbeOk.Check(clientVersion) {
t.Skipf("skipping due to version constraint %s", compatibility.BpIbaProbeOk)
}

bpClient := testutils.MakeOrFindBlueprint(t, ctx, "BPA", testutils.BlueprintA)

type testCase struct {
Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/blueprint_iba_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ subcategory: "Reference Design: Shared"
description: |-
This data source provides details of a specific IBA Dashboard in a Blueprint.
At least one optional attribute is required.
Note: Compatible only with Apstra <5.0.0
---

# apstra_blueprint_iba_dashboard (Data Source)
Expand All @@ -12,6 +13,8 @@ This data source provides details of a specific IBA Dashboard in a Blueprint.

At least one optional attribute is required.

*Note: Compatible only with Apstra <5.0.0*


## Example Usage

Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/blueprint_iba_dashboards.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ page_title: "apstra_blueprint_iba_dashboards Data Source - terraform-provider-ap
subcategory: "Reference Design: Shared"
description: |-
This data source returns the ID numbers of all IBA Dashboards in a Blueprint.
Note: Compatible only with Apstra <5.0.0
---

# apstra_blueprint_iba_dashboards (Data Source)

This data source returns the ID numbers of all IBA Dashboards in a Blueprint.

*Note: Compatible only with Apstra <5.0.0*


## Example Usage

Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/blueprint_iba_predefined_probe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ page_title: "apstra_blueprint_iba_predefined_probe Data Source - terraform-provi
subcategory: "Reference Design: Shared"
description: |-
This data source provides details of a specific IBA Predefined Probe in a Blueprint.
Note: Compatible only with Apstra <5.0.0
---

# apstra_blueprint_iba_predefined_probe (Data Source)

This data source provides details of a specific IBA Predefined Probe in a Blueprint.

*Note: Compatible only with Apstra <5.0.0*


## Example Usage

Expand Down
3 changes: 3 additions & 0 deletions docs/resources/blueprint_iba_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ page_title: "apstra_blueprint_iba_dashboard Resource - terraform-provider-apstra
subcategory: "Reference Design: Shared"
description: |-
This resource creates a IBA Dashboard.
Note: Compatible only with Apstra <5.0.0
---

# apstra_blueprint_iba_dashboard (Resource)

This resource creates a IBA Dashboard.

*Note: Compatible only with Apstra <5.0.0*


## Example Usage

Expand Down

0 comments on commit 3730466

Please sign in to comment.