Skip to content

Commit

Permalink
Merge pull request #1016 from Juniper/1015-apstra_datacenter_connecti…
Browse files Browse the repository at this point in the history
…vity_template_interface-fails-to-set-subpolicies-within-vn_single

Bugfix: `vn_single` primitives do not handle sub policies correctly.
  • Loading branch information
chrismarget-j authored Jan 20, 2025
2 parents d5222bb + f33bbeb commit 7931503
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (o VirtualNetworkSingle) primitive(ctx context.Context, diags *diag.Diagnos
result.BatchId = (*apstra.ObjectId)(o.BatchId.ValueStringPointer()) // nil when null
}

result.Subpolicies = append(result.Subpolicies, BgpPeeringGenericSystemSubpolicies(ctx, o.BgpPeeringGenericSystems, diags)...)
result.Subpolicies = append(result.Subpolicies, StaticRouteSubpolicies(ctx, o.StaticRoutes, diags)...)

return &result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,22 +642,48 @@ func randomStaticRoutePrimitives(t testing.TB, _ context.Context, ipv4Count, ipv
}

const resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingleHCL = `{
virtual_network_id = %q
tagged = %q
virtual_network_id = %q
tagged = %q
bgp_peering_generic_systems = %s
static_routes = %s
},
`

type resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingle struct {
virtualNetworkId string
tagged bool
virtualNetworkId string
tagged bool
bgpPeeringGenericSystems map[string]resourceDataCenterConnectivityTemplatePrimitiveBgpPeeringGenericSystem
staticRoutes map[string]resourceDataCenterConnectivityTemplatePrimitiveStaticRoute
}

func (o resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingle) render(indent int) string {
bgpPeeringGenericSystems := "null"
if len(o.bgpPeeringGenericSystems) > 0 {
sb := new(strings.Builder)
for k, v := range o.bgpPeeringGenericSystems {
sb.WriteString(tfapstra.Indent(indent, k+" = "+v.render(indent)))
}

bgpPeeringGenericSystems = "{\n" + sb.String() + " }"
}

staticRoutes := "null"
if len(o.staticRoutes) > 0 {
sb := new(strings.Builder)
for k, v := range o.staticRoutes {
sb.WriteString(tfapstra.Indent(indent, k+" = "+v.render(indent)))
}

staticRoutes = "{\n" + sb.String() + " }"
}

return tfapstra.Indent(
indent,
fmt.Sprintf(resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingleHCL,
o.virtualNetworkId,
strconv.FormatBool(o.tagged),
bgpPeeringGenericSystems,
staticRoutes,
),
)
}
Expand All @@ -666,6 +692,14 @@ func (o resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingle) tes
var result [][]string
result = append(result, []string{"TestCheckResourceAttr", path + ".virtual_network_id", o.virtualNetworkId})
result = append(result, []string{"TestCheckResourceAttr", path + ".tagged", strconv.FormatBool(o.tagged)})
result = append(result, []string{"TestCheckResourceAttr", path + ".bgp_peering_generic_systems.%", strconv.Itoa(len(o.bgpPeeringGenericSystems))})
for k, v := range o.bgpPeeringGenericSystems {
result = append(result, v.testChecks(path+".bgp_peering_generic_systems."+k)...)
}
result = append(result, []string{"TestCheckResourceAttr", path + ".static_routes.%", strconv.Itoa(len(o.staticRoutes))})
for k, v := range o.staticRoutes {
result = append(result, v.testChecks(path+".static_routes."+k)...)
}
return result
}

Expand All @@ -675,8 +709,10 @@ func randomVirtualNetworkSingles(t testing.TB, ctx context.Context, count int, c
result := make(map[string]resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingle, count)
for range count {
result[acctest.RandStringFromCharSet(6, acctest.CharSetAlpha)] = resourceDataCenterConnectivityTemplatePrimitiveVirtualNetworkSingle{
virtualNetworkId: testutils.VirtualNetworkVxlan(t, ctx, client, cleanup).String(),
tagged: oneOf(true, false),
virtualNetworkId: testutils.VirtualNetworkVxlan(t, ctx, client, cleanup).String(),
tagged: oneOf(true, false),
bgpPeeringGenericSystems: randomBgpPeeringGenericSystemPrimitives(t, ctx, rand.IntN(3), client, cleanup),
staticRoutes: randomStaticRoutePrimitives(t, ctx, rand.IntN(3), rand.IntN(3), client, cleanup),
}
}

Expand Down

0 comments on commit 7931503

Please sign in to comment.