Skip to content

Commit

Permalink
iba probes are independent of datacenter type, should probably be cal…
Browse files Browse the repository at this point in the history
…led iba_widgets and not datacenter_iba_widget
  • Loading branch information
rajagopalans committed Oct 4, 2023
1 parent f4601e9 commit d48af32
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@ import (
"context"
"fmt"
"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"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 = &dataSourceDatacenterIbaWidget{}
var _ datasource.DataSourceWithConfigure = &dataSourceIbaWidget{}

type dataSourceDatacenterIbaWidget struct {
type dataSourceIbaWidget struct {
client *apstra.Client
}

func (o *dataSourceDatacenterIbaWidget) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_datacenter_iba_widget"
func (o *dataSourceIbaWidget) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_iba_widget"
}

func (o *dataSourceDatacenterIbaWidget) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (o *dataSourceIbaWidget) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
o.client = DataSourceGetClient(ctx, req, resp)
}

func (o *dataSourceDatacenterIbaWidget) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (o *dataSourceIbaWidget) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "This data source provides details of a specific IBA Widget in a Blueprint." +
"\n\n" +
"At least one optional attribute is required.",
Attributes: blueprint.IbaWidget{}.DataSourceAttributes(),
Attributes: iba.IbaWidget{}.DataSourceAttributes(),
}
}

func (o *dataSourceDatacenterIbaWidget) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.IbaWidget
func (o *dataSourceIbaWidget) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config iba.IbaWidget
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (

const (
dataSourceDatacenterIbaWidgetTemplateByNameHCL = `
data "apstra_datacenter_iba_widget" "test" {
data "apstra_iba_widget" "test" {
blueprint_id = "%s"
name = "%s"
}
`

dataSourceDatacenterIbaWidgetTemplateByIdHCL = `
data "apstra_datacenter_iba_widget" "test" {
data "apstra_iba_widget" "test" {
blueprint_id = "%s"
id = "%s"
}
Expand Down Expand Up @@ -61,8 +61,8 @@ func TestAccDataSourceDatacenterIbaWidget(t *testing.T) {
Config: insecureProviderConfigHCL + fmt.Sprintf(dataSourceDatacenterIbaWidgetTemplateByIdHCL,
string(bpClient.Id()), string(widgetIdA)),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.apstra_datacenter_iba_widget.test", "id", widgetIdA.String()),
resource.TestCheckResourceAttr("data.apstra_datacenter_iba_widget.test", "name",
resource.TestCheckResourceAttr("data.apstra_iba_widget.test", "id", widgetIdA.String()),
resource.TestCheckResourceAttr("data.apstra_iba_widget.test", "name",
widgetDataA.Label),
),
},
Expand All @@ -71,8 +71,8 @@ func TestAccDataSourceDatacenterIbaWidget(t *testing.T) {
Config: insecureProviderConfigHCL + fmt.Sprintf(dataSourceDatacenterIbaWidgetTemplateByNameHCL,
string(bpClient.Id()), widgetDataA.Label),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.apstra_datacenter_iba_widget.test", "id", widgetIdA.String()),
resource.TestCheckResourceAttr("data.apstra_datacenter_iba_widget.test", "name",
resource.TestCheckResourceAttr("data.apstra_iba_widget.test", "id", widgetIdA.String()),
resource.TestCheckResourceAttr("data.apstra_iba_widget.test", "name",
widgetDataA.Label),
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

var _ datasource.DataSourceWithConfigure = &dataSourceDatacenterIbaWidgets{}
var _ datasource.DataSourceWithConfigure = &dataSourceIbaWidgets{}

type dataSourceDatacenterIbaWidgets struct {
type dataSourceIbaWidgets struct {
client *apstra.Client
}

func (o *dataSourceDatacenterIbaWidgets) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_datacenter_iba_widgets"
func (o *dataSourceIbaWidgets) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_iba_widgets"
}

func (o *dataSourceDatacenterIbaWidgets) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (o *dataSourceIbaWidgets) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
o.client = DataSourceGetClient(ctx, req, resp)
}

func (o *dataSourceDatacenterIbaWidgets) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (o *dataSourceIbaWidgets) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "This data source returns the IDs of the IBA Widgets in a Blueprint.",
Attributes: map[string]schema.Attribute{
Expand All @@ -46,7 +46,7 @@ func (o *dataSourceDatacenterIbaWidgets) Schema(_ context.Context, _ datasource.
}
}

func (o *dataSourceDatacenterIbaWidgets) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (o *dataSourceIbaWidgets) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config struct {
BlueprintId types.String `tfsdk:"blueprint_id"`
Ids types.Set `tfsdk:"ids"`
Expand Down
2 changes: 1 addition & 1 deletion apstra/blueprint/iba_widget.go → apstra/iba/widget.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package blueprint
package iba

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions apstra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource
func() datasource.DataSource { return &dataSourceDatacenterCtStaticRoute{} },
func() datasource.DataSource { return &dataSourceDatacenterCtVnSingle{} },
func() datasource.DataSource { return &dataSourceDatacenterCtVnMultiple{} },
func() datasource.DataSource { return &dataSourceDatacenterIbaWidget{} },
func() datasource.DataSource { return &dataSourceDatacenterIbaWidgets{} },
func() datasource.DataSource { return &dataSourceIbaWidget{} },
func() datasource.DataSource { return &dataSourceIbaWidgets{} },
func() datasource.DataSource { return &dataSourceDatacenterPropertySet{} },
func() datasource.DataSource { return &dataSourceDatacenterPropertySets{} },
func() datasource.DataSource { return &dataSourceDatacenterRoutingPolicy{} },
Expand Down
55 changes: 0 additions & 55 deletions docs/data-sources/datacenter_iba_widget.md

This file was deleted.

61 changes: 0 additions & 61 deletions docs/data-sources/datacenter_iba_widgets.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ data "apstra_datacenter_blueprint" "b" {
name = "test"
}

data "apstra_datacenter_iba_widget" "i" {
data "apstra_iba_widget" "i" {
blueprint_id = data.apstra_datacenter_blueprint.b.id
label = "Fabric ECMP Imbalance"
name = "Fabric ECMP Imbalance"
}
output "o" {
value = data.apstra_datacenter_iba_widget.i
value = data.apstra_iba_widget.i
}

#Output looks like this
#o = {
# "blueprint_id" = "cff966ad-f85f-478f-bae5-b64c1e58d31f"
# "description" = "Number of systems with ECMP imbalance."
# "id" = "d03ba5ad-77f4-4198-8901-3c03fea7e341"
# "label" = "Fabric ECMP Imbalance"
# "name" = "Fabric ECMP Imbalance"
#}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ data "apstra_datacenter_blueprint" "b" {
name = "test"
}

data "apstra_datacenter_iba_widgets" "all" {
data "apstra_iba_widgets" "all" {
blueprint_id = data.apstra_datacenter_blueprint.b.id
}


data "apstra_datacenter_iba_widget" "all" {
for_each = data.apstra_datacenter_iba_widgets.all.ids
data "apstra_iba_widget" "all" {
for_each = data.apstra_iba_widgets.all.ids
blueprint_id = data.apstra_datacenter_blueprint.b.id
id = each.key
}

output "o" {
value = data.apstra_datacenter_iba_widget.all
value = data.apstra_iba_widget.all
}

#Output looks something like this
Expand All @@ -25,12 +25,12 @@ output "o" {
# "blueprint_id" = "cff966ad-f85f-478f-bae5-b64c1e58d31f"
# "description" = ""
# "id" = "2e6466ad-ed96-4773-9b55-87c7607e30ed"
# "label" = "Systems with high interface utilization"
# "name" = "Systems with high interface utilization"
# }
# "555fcdd7-ce9b-4bbb-9f90-43b921afe1d2" = {
# "blueprint_id" = "cff966ad-f85f-478f-bae5-b64c1e58d31f"
# "description" = ""
# "id" = "555fcdd7-ce9b-4bbb-9f90-43b921afe1d2"
# "label" = "Systems with high memory utilization"
# "name" = "Systems with high memory utilization"
# }
#}

0 comments on commit d48af32

Please sign in to comment.