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

Add checks for unknown values to ValidateConfig() methods #718

Merged
merged 1 commit into from
Jul 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (o *dataSourceDatacenterCtBgpPeeringGenericSystem) ValidateConfig(ctx conte
return
}

if config.Ipv4AddressingType.IsUnknown() || config.Ipv6AddressingType.IsUnknown() {
return //cannot validate until both values are known
}

v4NoneString := apstra.CtPrimitiveIPv4ProtocolSessionAddressingNone.String() // "none"
v6NoneString := apstra.CtPrimitiveIPv6ProtocolSessionAddressingNone.String() // "none"

Expand Down
4 changes: 4 additions & 0 deletions apstra/data_source_datacenter_ct_dynamic_bgp_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (o *dataSourceDatacenterCtDynamicBgpPeering) ValidateConfig(ctx context.Con
return
}

if config.Ipv4Enabled.IsUnknown() || config.Ipv6Enabled.IsUnknown() {
return // cannot validate while either value is unknown
}

if !config.Ipv4Enabled.ValueBool() && !config.Ipv6Enabled.ValueBool() {
resp.Diagnostics.AddError("Invalid Attribute Combination", "At least one attribute "+
"out of 'ipv4_enabled' and 'ipv6_enabled' must be `true`")
Expand Down
4 changes: 4 additions & 0 deletions apstra/design/logical_device_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func (o *LogicalDevicePanel) Validate(ctx context.Context, i int, diags *diag.Di
// count up the ports in each port group
var panelPortsByPortGroup int64
for _, portGroup := range portGroups {
if portGroup.PortCount.IsUnknown() {
return // cannot validate with any unknown port count
}

panelPortsByPortGroup = panelPortsByPortGroup + portGroup.PortCount.ValueInt64()
}

Expand Down
4 changes: 4 additions & 0 deletions apstra/design/template_pod_based.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func (o *TemplatePodBased) CopyWriteOnlyElements(ctx context.Context, src *Templ
func (o TemplatePodBased) VersionConstraints() apiversions.Constraints {
var response apiversions.Constraints

if o.FabricAddressing.IsUnknown() {
return apiversions.Constraints{} // cannot validate
}

if !o.FabricAddressing.IsNull() {
response.AddAttributeConstraints(
apiversions.AttributeConstraint{
Expand Down
4 changes: 4 additions & 0 deletions apstra/design/template_rack_based.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ func (o *TemplateRackBased) CopyWriteOnlyElements(ctx context.Context, src *Temp
func (o TemplateRackBased) VersionConstraints() apiversions.Constraints {
var response apiversions.Constraints

if o.FabricAddressing.IsUnknown() {
return apiversions.Constraints{} // cannot validate
}

if !o.FabricAddressing.IsNull() {
response.AddAttributeConstraints(
apiversions.AttributeConstraint{
Expand Down
4 changes: 4 additions & 0 deletions apstra/resource_configlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (o *resourceConfiglet) ValidateConfig(ctx context.Context, req resource.Val

// validate each generator
for i, generator := range generators {
if generator.ConfigStyle.IsUnknown() || generator.Section.IsUnknown() {
continue // cannot validate with unknown value
}

// extract the platform/config_style from the generator object as an SDK iota type
var platform apstra.PlatformOS
err := platform.FromString(generator.ConfigStyle.ValueString())
Expand Down
4 changes: 4 additions & 0 deletions apstra/resource_interface_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (o *resourceInterfaceMap) ValidateConfig(ctx context.Context, req resource.
logicalDevicePorts := make(map[string]struct{})

for _, configInterface := range configInterfaces {
if configInterface.PhysicalInterfaceName.IsUnknown() || configInterface.LogicalDevicePort.IsUnknown() {
continue // cannot validate
}

physicalInterfaceName := configInterface.PhysicalInterfaceName.ValueString()
logicalDevicePortName := configInterface.LogicalDevicePort.ValueString()

Expand Down
1 change: 1 addition & 0 deletions apstra/resource_logical_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (o *resourceLogicalDevice) ValidateConfig(ctx context.Context, req resource
if config.Panels.IsUnknown() {
return // cannot validate unknown panels
}

panels := config.GetPanels(ctx, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
Expand Down
4 changes: 4 additions & 0 deletions apstra/resource_modular_device_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (o *resourceModularDeviceProfile) ValidateConfig(ctx context.Context, req r
return
}

if config.LineCardProfileIds.IsUnknown() {
return //cannot validate
}

for key := range config.LineCardProfileIds.Elements() {
_, err := strconv.ParseUint(key, 10, 64)
if err != nil {
Expand Down
Loading