Skip to content

Commit

Permalink
Merge pull request #959 from Juniper/956-attribute-null_when_not_foun…
Browse files Browse the repository at this point in the history
…d-is-not-working-and-apply-fails-even-after-setting-it-as-true

Bug #956: honor`null_when_not_found` switch
  • Loading branch information
bwJuniper authored Oct 30, 2024
2 parents 2b696be + 2dd4fb5 commit c097d7f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apstra/blueprint/node_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blueprint
import (
"context"
"fmt"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
Expand Down Expand Up @@ -79,6 +80,10 @@ func (o *NodeTypeSystem) AttributesFromApi(ctx context.Context, client *apstra.C
case !o.Id.IsNull():
desiredNode, ok = nodeResponse.Nodes[o.Id.ValueString()]
if !ok {
if o.NullWhenNotFound.ValueBool() {
o.Attributes = types.ObjectNull(NodeTypeSystemAttributes{}.AttrTypes())
return
}
diags.AddError("Node not found",
fmt.Sprintf("Node with ID %q not found in blueprint %q",
o.Id.ValueString(), o.BlueprintId.ValueString()))
Expand All @@ -92,6 +97,10 @@ func (o *NodeTypeSystem) AttributesFromApi(ctx context.Context, client *apstra.C
}
}
if !ok {
if o.NullWhenNotFound.ValueBool() {
o.Attributes = types.ObjectNull(NodeTypeSystemAttributes{}.AttrTypes())
return
}
diags.AddError("Node not found",
fmt.Sprintf("Node with Name %q not found in blueprint %q",
o.Name.ValueString(), o.BlueprintId.ValueString()))
Expand Down

0 comments on commit c097d7f

Please sign in to comment.