Skip to content

Commit

Permalink
Invoke Resolve() to clean up paths in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Dec 19, 2024
1 parent e6c2022 commit 88bdf3b
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ func (o BgpPeeringGenericSystem) ResourceAttributes() map[string]resourceSchema.
Optional: true,
Validators: []validator.Int64{
int64validator.Between(constants.BgpKeepaliveMin, constants.BgpKeepaliveMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("hold_time")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("hold_time").Resolve()),
},
},
"hold_time": resourceSchema.Int64Attribute{
MarkdownDescription: "BGP hold time (seconds).",
Optional: true,
Validators: []validator.Int64{
int64validator.Between(constants.BgpHoldMin, constants.BgpHoldMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("keepalive_time")),
apstravalidator.AtLeastProductOf(3, path.MatchRelative().AtParent().AtName("keepalive_time")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("keepalive_time").Resolve()),
apstravalidator.AtLeastProductOf(3, path.MatchRelative().AtParent().AtName("keepalive_time").Resolve()),
},
},
"ipv4_addressing_type": resourceSchema.StringAttribute{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ func (o BgpPeeringIpEndpoint) ResourceAttributes() map[string]resourceSchema.Att
Optional: true,
Validators: []validator.Int64{
int64validator.Between(constants.BgpKeepaliveMin, constants.BgpKeepaliveMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("hold_time")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("hold_time").Resolve()),
},
},
"hold_time": resourceSchema.Int64Attribute{
MarkdownDescription: "BGP hold time (seconds).",
Optional: true,
Validators: []validator.Int64{
int64validator.Between(constants.BgpHoldMin, constants.BgpHoldMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("keepalive_time")),
apstravalidator.AtLeastProductOf(3, path.MatchRelative().AtParent().AtName("keepalive_time")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("keepalive_time").Resolve()),
apstravalidator.AtLeastProductOf(3, path.MatchRelative().AtParent().AtName("keepalive_time").Resolve()),
},
},
"local_asn": resourceSchema.Int64Attribute{
Expand All @@ -127,7 +127,7 @@ func (o BgpPeeringIpEndpoint) ResourceAttributes() map[string]resourceSchema.Att
Validators: []validator.String{
stringvalidator.AtLeastOneOf(path.Expressions{
path.MatchRelative(),
path.MatchRelative().AtParent().AtName("ipv6_address"),
path.MatchRelative().AtParent().AtName("ipv6_address").Resolve(),
}...),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ func (o DynamicBgpPeering) ResourceAttributes() map[string]resourceSchema.Attrib
Optional: true,
Validators: []validator.Int64{
int64validator.Between(constants.BgpKeepaliveMin, constants.BgpKeepaliveMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("hold_time")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("hold_time").Resolve()),
},
},
"hold_time": resourceSchema.Int64Attribute{
MarkdownDescription: "BGP hold time (seconds).",
Optional: true,
Validators: []validator.Int64{
int64validator.Between(constants.BgpHoldMin, constants.BgpHoldMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("keepalive_time")),
apstravalidator.AtLeastProductOf(3, path.MatchRelative().AtParent().AtName("keepalive_time")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("keepalive_time").Resolve()),
apstravalidator.AtLeastProductOf(3, path.MatchRelative().AtParent().AtName("keepalive_time").Resolve()),
},
},
"ipv4_enabled": resourceSchema.BoolAttribute{
Expand All @@ -131,17 +131,17 @@ func (o DynamicBgpPeering) ResourceAttributes() map[string]resourceSchema.Attrib
CustomType: cidrtypes.IPv4PrefixType{},
Optional: true,
Validators: []validator.String{
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv4_enabled"), types.BoolNull()),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv4_enabled"), types.BoolValue(false)),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv4_enabled").Resolve(), types.BoolNull()),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv4_enabled").Resolve(), types.BoolValue(false)),
},
},
"ipv6_peer_prefix": resourceSchema.StringAttribute{
MarkdownDescription: "IPv6 Subnet for BGP Prefix Dynamic Neighbors. Leave blank to derive subnet from application point.",
CustomType: cidrtypes.IPv6PrefixType{},
Optional: true,
Validators: []validator.String{
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv6_enabled"), types.BoolNull()),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv6_enabled"), types.BoolValue(false)),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv6_enabled").Resolve(), types.BoolNull()),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("ipv6_enabled").Resolve(), types.BoolValue(false)),
},
},
"routing_policies": resourceSchema.MapNestedAttribute{
Expand Down
6 changes: 3 additions & 3 deletions apstra/blueprint/datacenter_generic_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (o DatacenterGenericSystem) ResourceAttributes() map[string]resourceSchema.
Default: int64default.StaticInt64(design.PoIdMin),
Validators: []validator.Int64{
int64validator.Between(design.PoIdMin, design.PoIdMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_max")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_max").Resolve()),
},
},
"port_channel_id_max": resourceSchema.Int64Attribute{
Expand All @@ -135,8 +135,8 @@ func (o DatacenterGenericSystem) ResourceAttributes() map[string]resourceSchema.
Default: int64default.StaticInt64(design.PoIdMin),
Validators: []validator.Int64{
int64validator.Between(design.PoIdMin, design.PoIdMax),
int64validator.AtLeastSumOf(path.MatchRelative().AtParent().AtName("port_channel_id_min")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_min")),
int64validator.AtLeastSumOf(path.MatchRelative().AtParent().AtName("port_channel_id_min").Resolve()),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_min").Resolve()),
},
},
"external": resourceSchema.BoolAttribute{
Expand Down
4 changes: 2 additions & 2 deletions apstra/blueprint/datacenter_security_policy_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ func (o DatacenterSecurityPolicyRule) ResourceAttributes() map[string]resourceSc
Computed: true,
Validators: []validator.Bool{
apstravalidator.WhenValueAtMustBeBool(
path.MatchRelative().AtParent().AtName("protocol"),
path.MatchRelative().AtParent().AtName("protocol").Resolve(),
types.StringValue(enum.PolicyRuleProtocolTcp.Value),
apstravalidator.ValueAtMustBeBool(
path.MatchRelative().AtParent().AtName("protocol"),
path.MatchRelative().AtParent().AtName("protocol").Resolve(),
types.StringValue(enum.PolicyRuleProtocolTcp.Value),
true,
),
Expand Down
2 changes: 1 addition & 1 deletion apstra/blueprint/datacenter_security_policy_rule_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (o DatacenterSecurityPolicyRulePortRange) ResourceAttributes() map[string]r
Required: true,
Validators: []validator.Int64{
int64validator.Between(1, 65535),
int64validator.AtLeastSumOf(path.MatchRelative().AtParent().AtName("from_port")),
int64validator.AtLeastSumOf(path.MatchRelative().AtParent().AtName("from_port").Resolve()),
},
},
}
Expand Down
26 changes: 13 additions & 13 deletions apstra/blueprint/datacenter_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
apstravalidator.RequiredWhenValueIs(
path.MatchRelative().AtParent().AtName("type"),
path.MatchRelative().AtParent().AtName("type").Resolve(),
types.StringValue(enum.VnTypeVxlan.String()),
),
apstravalidator.RequiredWhenValueNull(
path.MatchRelative().AtParent().AtName("type"),
path.MatchRelative().AtParent().AtName("type").Resolve(),
),
},
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
Expand All @@ -342,7 +342,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.Int64{
int64validator.Between(constants.VniMin, constants.VniMax),
apstravalidator.ForbiddenWhenValueIs(
path.MatchRelative().AtParent().AtName("type"),
path.MatchRelative().AtParent().AtName("type").Resolve(),
types.StringValue(enum.VnTypeVlan.String()),
),
},
Expand All @@ -361,7 +361,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.Bool{
apstravalidator.WhenValueIsBool(types.BoolValue(true),
apstravalidator.ValueAtMustBeBool(
path.MatchRelative().AtParent().AtName("type"),
path.MatchRelative().AtParent().AtName("type").Resolve(),
types.StringValue(enum.VnTypeVxlan.String()),
false,
),
Expand All @@ -381,7 +381,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.Map{
mapvalidator.SizeAtLeast(1),
apstravalidator.WhenValueAtMustBeMap(
path.MatchRelative().AtParent().AtName("type"),
path.MatchRelative().AtParent().AtName("type").Resolve(),
types.StringValue(enum.VnTypeVlan.String()),
mapvalidator.SizeAtMost(1),
),
Expand All @@ -398,8 +398,8 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.Bool{
apstravalidator.WhenValueIsBool(types.BoolValue(true),
apstravalidator.AlsoRequiresNOf(1,
path.MatchRelative().AtParent().AtName("ipv4_connectivity_enabled"),
path.MatchRelative().AtParent().AtName("ipv6_connectivity_enabled"),
path.MatchRelative().AtParent().AtName("ipv4_connectivity_enabled").Resolve(),
path.MatchRelative().AtParent().AtName("ipv6_connectivity_enabled").Resolve(),
),
),
},
Expand Down Expand Up @@ -427,7 +427,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
apstravalidator.ParseCidr(true, false),
apstravalidator.WhenValueSetString(
apstravalidator.ValueAtMustBeString(
path.MatchRelative().AtParent().AtName("ipv4_connectivity_enabled"),
path.MatchRelative().AtParent().AtName("ipv4_connectivity_enabled").Resolve(),
types.BoolValue(true), false,
),
),
Expand All @@ -444,7 +444,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
apstravalidator.ParseCidr(false, true),
apstravalidator.WhenValueSetString(
apstravalidator.ValueAtMustBeString(
path.MatchRelative().AtParent().AtName("ipv6_connectivity_enabled"),
path.MatchRelative().AtParent().AtName("ipv6_connectivity_enabled").Resolve(),
types.BoolValue(true), false,
),
),
Expand All @@ -459,7 +459,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
apstravalidator.WhenValueIsBool(
types.BoolValue(true),
apstravalidator.ValueAtMustBeBool(
path.MatchRelative().AtParent().AtName("ipv4_connectivity_enabled"),
path.MatchRelative().AtParent().AtName("ipv4_connectivity_enabled").Resolve(),
types.BoolValue(true),
false,
),
Expand All @@ -475,7 +475,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
apstravalidator.WhenValueIsBool(
types.BoolValue(true),
apstravalidator.ValueAtMustBeBool(
path.MatchRelative().AtParent().AtName("ipv6_connectivity_enabled"),
path.MatchRelative().AtParent().AtName("ipv6_connectivity_enabled").Resolve(),
types.BoolValue(true),
false,
),
Expand All @@ -491,7 +491,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.String{
apstravalidator.ParseIp(true, false),
apstravalidator.FallsWithinCidr(
path.MatchRelative().AtParent().AtName("ipv4_subnet"),
path.MatchRelative().AtParent().AtName("ipv4_subnet").Resolve(),
false, false),
},
},
Expand All @@ -504,7 +504,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
Validators: []validator.String{
apstravalidator.ParseIp(false, true),
apstravalidator.FallsWithinCidr(
path.MatchRelative().AtParent().AtName("ipv6_subnet"),
path.MatchRelative().AtParent().AtName("ipv6_subnet").Resolve(),
true, true),
},
},
Expand Down
6 changes: 3 additions & 3 deletions apstra/blueprint/rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func (o Rack) ResourceAttributes() map[string]resourceSchema.Attribute {
"to the `name` attribute will not affect the names of those systems. It's a create-time one-shot operation.",
Optional: true,
Validators: []validator.Bool{
boolvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("name")),
boolvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("name").Resolve()),
apstravalidator.MustBeOneOf([]attr.Value{
types.BoolValue(true),
types.BoolNull(),
}),
boolvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("rack_elements_name_one_shot")),
boolvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("rack_elements_name_one_shot").Resolve()),
},
},
"rack_elements_name_one_shot": resourceSchema.BoolAttribute{
Expand All @@ -83,7 +83,7 @@ func (o Rack) ResourceAttributes() map[string]resourceSchema.Attribute {
"changes to the `name` attribute will not affect those elements. It's a create-time operation only.",
Optional: true,
Validators: []validator.Bool{
boolvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("name")),
boolvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("name").Resolve()),
apstravalidator.MustBeOneOf([]attr.Value{
types.BoolValue(true),
types.BoolNull(),
Expand Down
8 changes: 4 additions & 4 deletions apstra/design/rack_type_generic_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (o GenericSystem) ResourceAttributes() map[string]resourceSchema.Attribute
Computed: true,
Validators: []validator.Int64{
int64validator.Between(PoIdMin, PoIdMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_max")),
int64validator.AtMostSumOf(path.MatchRelative().AtParent().AtName("port_channel_id_max")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_max").Resolve()),
int64validator.AtMostSumOf(path.MatchRelative().AtParent().AtName("port_channel_id_max").Resolve()),
},
},
"port_channel_id_max": resourceSchema.Int64Attribute{
Expand All @@ -113,8 +113,8 @@ func (o GenericSystem) ResourceAttributes() map[string]resourceSchema.Attribute
Computed: true,
Validators: []validator.Int64{
int64validator.Between(PoIdMin, PoIdMax),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_min")),
int64validator.AtLeastSumOf(path.MatchRelative().AtParent().AtName("port_channel_id_min")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("port_channel_id_min").Resolve()),
int64validator.AtLeastSumOf(path.MatchRelative().AtParent().AtName("port_channel_id_min").Resolve()),
},
},
"count": resourceSchema.Int64Attribute{
Expand Down
6 changes: 3 additions & 3 deletions apstra/design/rack_type_leaf_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ func (o LeafSwitch) ResourceAttributes() map[string]resourceSchema.Attribute {
Optional: true,
Attributes: MlagInfo{}.ResourceAttributes(),
Validators: []validator.Object{
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()),
apstravalidator.RequiredWhenValueIs(path.MatchRelative().AtParent().AtName("redundancy_protocol").Resolve(), types.StringValue(apstra.LeafRedundancyProtocolMlag.String())),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("redundancy_protocol").Resolve(), types.StringValue(apstra.LeafRedundancyProtocolEsi.String())),
apstravalidator.ForbiddenWhenValueIs(path.MatchRelative().AtParent().AtName("redundancy_protocol").Resolve(), types.StringNull()),
},
},
"redundancy_protocol": resourceSchema.StringAttribute{
Expand Down
16 changes: 8 additions & 8 deletions apstra/design/rack_type_mlag_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (o MlagInfo) ResourceAttributes() map[string]resourceSchema.Attribute {
Required: true,
Validators: []validator.Int64{
int64validator.Between(PoIdMin, PoIdMax),
apstravalidator.DifferentFrom(path.MatchRelative().AtParent().AtName("l3_peer_link_port_channel_id")),
apstravalidator.DifferentFrom(path.MatchRelative().AtParent().AtName("l3_peer_link_port_channel_id").Resolve()),
},
},
"l3_peer_link_count": resourceSchema.Int64Attribute{
Expand All @@ -92,8 +92,8 @@ func (o MlagInfo) ResourceAttributes() map[string]resourceSchema.Attribute {
Validators: []validator.Int64{
int64validator.AtLeast(1),
int64validator.AlsoRequires(
path.MatchRelative().AtParent().AtName("l3_peer_link_speed"),
path.MatchRelative().AtParent().AtName("l3_peer_link_port_channel_id"),
path.MatchRelative().AtParent().AtName("l3_peer_link_speed").Resolve(),
path.MatchRelative().AtParent().AtName("l3_peer_link_port_channel_id").Resolve(),
),
},
},
Expand All @@ -103,8 +103,8 @@ func (o MlagInfo) ResourceAttributes() map[string]resourceSchema.Attribute {
Validators: []validator.String{
apstravalidator.ParseSpeed(),
stringvalidator.AlsoRequires(
path.MatchRelative().AtParent().AtName("l3_peer_link_count"),
path.MatchRelative().AtParent().AtName("l3_peer_link_port_channel_id"),
path.MatchRelative().AtParent().AtName("l3_peer_link_count").Resolve(),
path.MatchRelative().AtParent().AtName("l3_peer_link_port_channel_id").Resolve(),
),
},
},
Expand All @@ -114,10 +114,10 @@ func (o MlagInfo) ResourceAttributes() map[string]resourceSchema.Attribute {
Validators: []validator.Int64{
int64validator.Between(PoIdMin, PoIdMax),
int64validator.AlsoRequires(
path.MatchRelative().AtParent().AtName("l3_peer_link_count"),
path.MatchRelative().AtParent().AtName("l3_peer_link_speed"),
path.MatchRelative().AtParent().AtName("l3_peer_link_count").Resolve(),
path.MatchRelative().AtParent().AtName("l3_peer_link_speed").Resolve(),
),
apstravalidator.DifferentFrom(path.MatchRelative().AtParent().AtName("peer_link_port_channel_id")),
apstravalidator.DifferentFrom(path.MatchRelative().AtParent().AtName("peer_link_port_channel_id").Resolve()),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions apstra/freeform/link_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (o LinkEndpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
MarkdownDescription: "The interface name, as found in the associated Device Profile, e.g. `xe-0/0/0`",
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
stringvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("transformation_id")),
stringvalidator.AlsoRequires(path.MatchRelative().AtParent().AtName("transformation_id").Resolve()),
},
},
"interface_id": resourceSchema.StringAttribute{
Expand All @@ -92,7 +92,7 @@ func (o LinkEndpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
MarkdownDescription: "ID # of the transformation in the Device Profile",
Validators: []validator.Int64{
int64validator.AtLeast(1),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("interface_name")),
int64validator.AlsoRequires(path.MatchRelative().AtParent().AtName("interface_name").Resolve()),
},
},
"ipv4_address": resourceSchema.StringAttribute{
Expand Down
Loading

0 comments on commit 88bdf3b

Please sign in to comment.