Skip to content

Commit 8ce5870

Browse files
committed
feat(specs): Add codegen specs and acceptance tests for virtual router static routes
1 parent bf4aafa commit 8ce5870

6 files changed

+1479
-698
lines changed

assets/pango/example/main.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -195,35 +195,6 @@ func checkVr(c *pango.Client, ctx context.Context) {
195195
Enable: util.Bool(false),
196196
},
197197
},
198-
RoutingTable: &virtual_router.RoutingTable{
199-
// Ip: &virtual_router.RoutingTableIp{
200-
// StaticRoutes: []virtual_router.RoutingTableIpStaticRoutes{
201-
// {
202-
// Name: "default",
203-
// Destination: util.String("0.0.0.0/0"),
204-
// Interface: util.String("ethernet1/2"),
205-
// NextHop: &virtual_router.RoutingTableIpStaticRoutesNextHop{
206-
// IpAddress: util.String("1.1.1.1"),
207-
// },
208-
// Metric: util.Int(64),
209-
// AdminDist: util.Int(120),
210-
// },
211-
// },
212-
// },
213-
// Ipv6: &virtual_router.RoutingTableIpv6{
214-
// StaticRoutes: []virtual_router.RoutingTableIpv6StaticRoutes{
215-
// {
216-
// Name: "default",
217-
// Destination: util.String("0.0.0.0/0"),
218-
// NextHop: &virtual_router.RoutingTableIpv6StaticRoutesNextHop{
219-
// Ipv6Address: util.String("2001:0000:130F:0000:0000:09C0:876A:230D"),
220-
// },
221-
// Metric: util.Int(24),
222-
// AdminDist: util.Int(20),
223-
// },
224-
// },
225-
// },
226-
},
227198
Ecmp: &virtual_router.Ecmp{
228199
Enable: util.Bool(true),
229200
SymmetricReturn: util.Bool(true),
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
package provider_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/config"
8+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
11+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
12+
//"github.com/hashicorp/terraform-plugin-testing/terraform"
13+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
14+
)
15+
16+
func TestAccVirtualRouterStaticRouteIpv4(t *testing.T) {
17+
nameSuffix := acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum)
18+
prefix := fmt.Sprintf("test-acc-%s", nameSuffix)
19+
20+
location := config.ObjectVariable(map[string]config.Variable{
21+
"template": config.ObjectVariable(map[string]config.Variable{
22+
"name": config.StringVariable(prefix),
23+
}),
24+
})
25+
26+
resource.ParallelTest(t, resource.TestCase{
27+
PreCheck: func() { testAccPreCheck(t) },
28+
ProtoV6ProviderFactories: testAccProviders,
29+
Steps: []resource.TestStep{
30+
{
31+
Config: virtualRouterStaticRouteIpv4Tmpl1,
32+
ConfigVariables: map[string]config.Variable{
33+
"location": location,
34+
"prefix": config.StringVariable(prefix),
35+
},
36+
ConfigStateChecks: []statecheck.StateCheck{
37+
statecheck.ExpectKnownValue(
38+
"panos_virtual_router_static_route_ipv4.example",
39+
tfjsonpath.New("name"),
40+
knownvalue.StringExact(prefix),
41+
),
42+
statecheck.ExpectKnownValue(
43+
"panos_virtual_router_static_route_ipv4.example",
44+
tfjsonpath.New("admin_dist"),
45+
knownvalue.Int64Exact(15),
46+
),
47+
statecheck.ExpectKnownValue(
48+
"panos_virtual_router_static_route_ipv4.example",
49+
tfjsonpath.New("destination"),
50+
knownvalue.StringExact("192.168.2.0/24"),
51+
),
52+
statecheck.ExpectKnownValue(
53+
"panos_virtual_router_static_route_ipv4.example",
54+
tfjsonpath.New("interface"),
55+
knownvalue.StringExact("ethernet1/1"),
56+
),
57+
statecheck.ExpectKnownValue(
58+
"panos_virtual_router_static_route_ipv4.example",
59+
tfjsonpath.New("metric"),
60+
knownvalue.Int64Exact(100),
61+
),
62+
statecheck.ExpectKnownValue(
63+
"panos_virtual_router_static_route_ipv4.example",
64+
tfjsonpath.New("nexthop"),
65+
knownvalue.ObjectExact(map[string]knownvalue.Check{
66+
"ip_address": knownvalue.StringExact("192.168.1.254"),
67+
"discard": knownvalue.Null(),
68+
"fqdn": knownvalue.Null(),
69+
"next_vr": knownvalue.Null(),
70+
"receive": knownvalue.Null(),
71+
}),
72+
),
73+
statecheck.ExpectKnownValue(
74+
"panos_virtual_router_static_route_ipv4.example",
75+
tfjsonpath.New("path_monitor"),
76+
knownvalue.ObjectExact(map[string]knownvalue.Check{
77+
"enable": knownvalue.Bool(true),
78+
"failure_condition": knownvalue.StringExact("any"),
79+
"hold_time": knownvalue.Int64Exact(2),
80+
"monitor_destinations": knownvalue.ListExact([]knownvalue.Check{
81+
knownvalue.ObjectExact(map[string]knownvalue.Check{
82+
"name": knownvalue.StringExact("dest-1"),
83+
"enable": knownvalue.Bool(true),
84+
"source": knownvalue.StringExact("192.168.1.1/32"),
85+
"destination": knownvalue.StringExact("192.168.1.254"),
86+
"interval": knownvalue.Int64Exact(3),
87+
"count": knownvalue.Int64Exact(5),
88+
}),
89+
}),
90+
}),
91+
),
92+
statecheck.ExpectKnownValue(
93+
"panos_virtual_router_static_route_ipv4.example",
94+
tfjsonpath.New("route_table"),
95+
knownvalue.ObjectExact(map[string]knownvalue.Check{
96+
"unicast": knownvalue.MapExact(map[string]knownvalue.Check{}),
97+
"both": knownvalue.Null(),
98+
"multicast": knownvalue.Null(),
99+
"no_install": knownvalue.Null(),
100+
}),
101+
),
102+
statecheck.ExpectKnownValue(
103+
"panos_virtual_router_static_route_ipv4.example2",
104+
tfjsonpath.New("nexthop"),
105+
knownvalue.ObjectExact(map[string]knownvalue.Check{
106+
"ip_address": knownvalue.Null(),
107+
"discard": knownvalue.Null(),
108+
"fqdn": knownvalue.Null(),
109+
"next_vr": knownvalue.StringExact(fmt.Sprintf("%s-vr1", prefix)),
110+
"receive": knownvalue.Null(),
111+
}),
112+
),
113+
},
114+
},
115+
},
116+
})
117+
}
118+
119+
const virtualRouterStaticRouteIpv4Tmpl1 = `
120+
variable "location" { type = any }
121+
variable "prefix" { type = string }
122+
123+
resource "panos_template" "example" {
124+
location = { panorama = {} }
125+
126+
name = var.prefix
127+
}
128+
129+
resource "panos_ethernet_interface" "example" {
130+
location = var.location
131+
132+
name = "ethernet1/1"
133+
134+
layer3 = {
135+
ips = [{name = "192.168.1.1/32"}]
136+
}
137+
}
138+
139+
resource "panos_virtual_router" "example" {
140+
depends_on = [panos_template.example]
141+
142+
location = var.location
143+
144+
name = format("%s-vr1", var.prefix)
145+
146+
interfaces = [panos_ethernet_interface.example.name]
147+
}
148+
149+
resource "panos_virtual_router" "example2" {
150+
depends_on = [panos_template.example]
151+
152+
location = var.location
153+
154+
name = format("%s-vr2", var.prefix)
155+
}
156+
157+
resource "panos_virtual_router_static_route_ipv4" "example" {
158+
location = var.location
159+
160+
virtual_router = panos_virtual_router.example.name
161+
162+
name = var.prefix
163+
164+
admin_dist = 15
165+
destination = "192.168.2.0/24"
166+
interface = panos_ethernet_interface.example.name
167+
metric = 100
168+
169+
#bfd = {
170+
# profile = "BFD-profile"
171+
#}
172+
173+
nexthop = {
174+
ip_address = "192.168.1.254"
175+
}
176+
177+
path_monitor = {
178+
enable = true
179+
failure_condition = "any"
180+
hold_time = 2
181+
monitor_destinations = [{
182+
name = "dest-1"
183+
enable = true
184+
source = "192.168.1.1/32"
185+
destination = "192.168.1.254"
186+
interval = 3
187+
count = 5
188+
}]
189+
}
190+
191+
route_table = {
192+
unicast = {}
193+
}
194+
}
195+
196+
resource "panos_virtual_router_static_route_ipv4" "example2" {
197+
location = var.location
198+
199+
virtual_router = panos_virtual_router.example2.name
200+
201+
name = var.prefix
202+
203+
destination = "192.168.1.0/24"
204+
205+
nexthop = {
206+
next_vr = panos_virtual_router.example.name
207+
}
208+
}
209+
`

0 commit comments

Comments
 (0)