diff --git a/apstra/apstra_validator/forbidden_when_value_is.go b/apstra/apstra_validator/forbidden_when_value_is.go index 75ce298d..b58b888d 100644 --- a/apstra/apstra_validator/forbidden_when_value_is.go +++ b/apstra/apstra_validator/forbidden_when_value_is.go @@ -68,8 +68,7 @@ func (o ForbiddenWhenValueIsValidator) Validate(ctx context.Context, req Forbidd // get the attribute we'll be checking against var mpVal attr.Value - diags = req.Config.GetAttribute(ctx, mp, &mpVal) - resp.Diagnostics.Append(diags...) + resp.Diagnostics.Append(req.Config.GetAttribute(ctx, mp, &mpVal)...) if diags.HasError() { continue // Collect all errors } @@ -83,7 +82,7 @@ func (o ForbiddenWhenValueIsValidator) Validate(ctx context.Context, req Forbidd if o.Value.Equal(mpVal) { resp.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic( req.Path, - fmt.Sprintf("value not permitted when %q has value %s, got %q", mp, mpVal, req.ConfigValue), + fmt.Sprintf("attribute %q must be when %q has value %s, got: %q", req.Path, mp, mpVal, req.ConfigValue), )) } } diff --git a/apstra/apstra_validator/switch_lag_info.go b/apstra/apstra_validator/switch_lag_info.go deleted file mode 100644 index 8f618b5c..00000000 --- a/apstra/apstra_validator/switch_lag_info.go +++ /dev/null @@ -1,57 +0,0 @@ -package apstravalidator - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -var _ validator.Object = SwitchLagInfoValidator{} - -type SwitchLagInfoValidator struct { - redundancyProtocol string -} - -func (o SwitchLagInfoValidator) Description(_ context.Context) string { - return fmt.Sprintf("Ensures the sibling attribute 'redundancy_protocol' is set to '%s'.", o.redundancyProtocol) -} - -func (o SwitchLagInfoValidator) MarkdownDescription(ctx context.Context) string { - return o.Description(ctx) -} - -func (o SwitchLagInfoValidator) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) { - if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { - return - } - - redundancyProtocolPath := req.Path.ParentPath().AtName("redundancy_protocol") - - var redundancyProtocol types.String - resp.Diagnostics.Append(req.Config.GetAttribute(ctx, redundancyProtocolPath, &redundancyProtocol)...) - if resp.Diagnostics.HasError() { - return - } - - if redundancyProtocol.IsNull() || redundancyProtocol.IsUnknown() { - resp.Diagnostics.AddAttributeError( - req.Path, errInvalidConfig, - fmt.Sprintf("configuring '%s' requires '%s' = '%s'", req.Path.String(), redundancyProtocolPath.String(), o.redundancyProtocol), - ) - return - } - - if redundancyProtocol.ValueString() != o.redundancyProtocol { - resp.Diagnostics.AddAttributeError( - req.Path, errInvalidConfig, - fmt.Sprintf("configuring '%s' requires '%s' = '%s'", req.Path.String(), redundancyProtocolPath.String(), o.redundancyProtocol), - ) - } -} - -func ValidateSwitchLagInfo(m string) validator.Object { - return SwitchLagInfoValidator{ - redundancyProtocol: m, - } -} diff --git a/apstra/design/rack_type_leaf_switch.go b/apstra/design/rack_type_leaf_switch.go index 7977804e..1a130f34 100644 --- a/apstra/design/rack_type_leaf_switch.go +++ b/apstra/design/rack_type_leaf_switch.go @@ -108,7 +108,9 @@ func (o LeafSwitch) ResourceAttributes() map[string]resourceSchema.Attribute { Optional: true, Attributes: MlagInfo{}.ResourceAttributes(), Validators: []validator.Object{ - apstravalidator.ValidateSwitchLagInfo(apstra.LeafRedundancyProtocolMlag.String()), + apstravalidator.RequiredWhenValueIs(path.MatchRelative().AtParent().AtName("redundancy_protocol"), types.StringValue(apstra.LeafRedundancyProtocolMlag.String())), + apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("redundancy_protocol"), types.StringValue(apstra.LeafRedundancyProtocolEsi.String())), + apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("redundancy_protocol"), types.StringNull()), }, }, "redundancy_protocol": resourceSchema.StringAttribute{