Skip to content

Commit

Permalink
introduce apstra_blueprint_anomalies, deprecate apstra_anomalies
Browse files Browse the repository at this point in the history
…data sources
  • Loading branch information
chrismarget-j committed Sep 13, 2024
1 parent a3fa950 commit b0fb79b
Show file tree
Hide file tree
Showing 5 changed files with 881 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apstra/data_source_anomalies.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func (o *dataSourceAnomalies) Configure(ctx context.Context, req datasource.Conf

func (o *dataSourceAnomalies) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
DeprecationMessage: "This resource is deprecated and will be removed in a future version. Please migrate your" +
"configurations to use the `apstra_blueprint_anomalies` data source.",
MarkdownDescription: docCategoryRefDesignAny + "This data source provides per-node summary, " +
"per-service summary and full details of anomalies in the specified Blueprint.",
Attributes: blueprint.Anomalies{}.DataSourceAttributes(),
Expand Down
50 changes: 50 additions & 0 deletions apstra/data_source_blueprint_anomalies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tfapstra

import (
"context"
"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/blueprint"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
_ "github.com/hashicorp/terraform-plugin-framework/provider"
)

var _ datasource.DataSourceWithConfigure = &dataSourceAnomalies{}
var _ datasourceWithSetClient = &dataSourceAnomalies{}

type dataSourceBlueprintAnomalies struct {
client *apstra.Client
}

func (o *dataSourceBlueprintAnomalies) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_blueprint_anomalies"
}

func (o *dataSourceBlueprintAnomalies) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
configureDataSource(ctx, o, req, resp)
}

func (o *dataSourceBlueprintAnomalies) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: docCategoryRefDesignAny + "This data source provides per-node summary, " +
"per-service summary and full details of anomalies in the specified Blueprint.",
Attributes: blueprint.Anomalies{}.DataSourceAttributes(),
}
}

func (o *dataSourceBlueprintAnomalies) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config blueprint.Anomalies
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}

config.ReadFromApi(ctx, o.client, &resp.Diagnostics)

// set state
resp.Diagnostics.Append(resp.State.Set(ctx, &config)...)
}

func (o *dataSourceBlueprintAnomalies) setClient(client *apstra.Client) {
o.client = client
}
1 change: 1 addition & 0 deletions apstra/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource
func() datasource.DataSource { return &dataSourceAnomalies{} },
func() datasource.DataSource { return &dataSourceAsnPool{} },
func() datasource.DataSource { return &dataSourceAsnPools{} },
func() datasource.DataSource { return &dataSourceBlueprintAnomalies{} },
func() datasource.DataSource { return &dataSourceBlueprintDeploy{} },
func() datasource.DataSource { return &dataSourceBlueprintIbaPredefinedProbe{} },
func() datasource.DataSource { return &dataSourceBlueprintIbaWidget{} },
Expand Down
Loading

0 comments on commit b0fb79b

Please sign in to comment.