|
| 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