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

Rename anomalies data source #851

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 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
Loading