|
| 1 | +# Example 1: Basic virtual router with interfaces and administrative distances |
| 2 | +resource "panos_template" "basic" { |
| 3 | + location = { |
| 4 | + panorama = {} |
| 5 | + } |
| 6 | + name = "basic-vr-template" |
| 7 | +} |
| 8 | + |
| 9 | +resource "panos_ethernet_interface" "eth1" { |
| 10 | + location = { |
| 11 | + template = { |
| 12 | + vsys = "vsys1" |
| 13 | + name = panos_template.basic.name |
| 14 | + } |
| 15 | + } |
| 16 | + name = "ethernet1/1" |
| 17 | + layer3 = { |
| 18 | + mtu = 1500 |
| 19 | + ips = [{ name = "10.1.1.1/24" }] |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +resource "panos_ethernet_interface" "eth2" { |
| 24 | + location = { |
| 25 | + template = { |
| 26 | + vsys = "vsys1" |
| 27 | + name = panos_template.basic.name |
| 28 | + } |
| 29 | + } |
| 30 | + name = "ethernet1/2" |
| 31 | + layer3 = { |
| 32 | + mtu = 1500 |
| 33 | + ips = [{ name = "10.1.2.1/24" }] |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +resource "panos_virtual_router" "basic" { |
| 38 | + location = { |
| 39 | + template = { |
| 40 | + name = panos_template.basic.name |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + name = "production-vr" |
| 45 | + |
| 46 | + interfaces = [ |
| 47 | + panos_ethernet_interface.eth1.name, |
| 48 | + panos_ethernet_interface.eth2.name |
| 49 | + ] |
| 50 | + |
| 51 | + administrative_distances = { |
| 52 | + static = 10 |
| 53 | + static_ipv6 = 10 |
| 54 | + ospf_int = 30 |
| 55 | + ospf_ext = 110 |
| 56 | + ibgp = 200 |
| 57 | + ebgp = 20 |
| 58 | + rip = 120 |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +# Example 2: Virtual router with comprehensive BGP configuration |
| 63 | +resource "panos_template" "bgp" { |
| 64 | + location = { |
| 65 | + panorama = {} |
| 66 | + } |
| 67 | + name = "bgp-vr-template" |
| 68 | +} |
| 69 | + |
| 70 | +resource "panos_virtual_router" "bgp" { |
| 71 | + location = { |
| 72 | + template = { |
| 73 | + name = panos_template.bgp.name |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + name = "bgp-edge-router" |
| 78 | + |
| 79 | + protocol = { |
| 80 | + bgp = { |
| 81 | + # Core BGP settings |
| 82 | + enable = true |
| 83 | + router_id = "192.168.100.1" |
| 84 | + local_as = "65100" |
| 85 | + install_route = true |
| 86 | + reject_default_route = false |
| 87 | + allow_redist_default_route = true |
| 88 | + ecmp_multi_as = false |
| 89 | + enforce_first_as = true |
| 90 | + |
| 91 | + # BGP authentication profile |
| 92 | + auth_profile = [ |
| 93 | + { |
| 94 | + name = "bgp-auth-main" |
| 95 | + secret = "bgp-secure-password-2024" |
| 96 | + } |
| 97 | + ] |
| 98 | + |
| 99 | + # Peer groups: EBGP for external peers and IBGP for internal mesh |
| 100 | + peer_group = [ |
| 101 | + { |
| 102 | + name = "upstream-providers" |
| 103 | + enable = true |
| 104 | + type = { |
| 105 | + ebgp = { |
| 106 | + export_nexthop = "use-self" |
| 107 | + import_nexthop = "original" |
| 108 | + } |
| 109 | + } |
| 110 | + peer = [ |
| 111 | + { |
| 112 | + name = "isp-primary" |
| 113 | + enable = true |
| 114 | + local_ip = "192.168.100.1" |
| 115 | + peer_ip = "192.168.100.254" |
| 116 | + peer_as = "65000" |
| 117 | + }, |
| 118 | + { |
| 119 | + name = "isp-backup" |
| 120 | + enable = true |
| 121 | + local_ip = "192.168.100.1" |
| 122 | + peer_ip = "192.168.100.253" |
| 123 | + peer_as = "65001" |
| 124 | + } |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + name = "internal-mesh" |
| 129 | + enable = true |
| 130 | + type = { |
| 131 | + ibgp = {} |
| 132 | + } |
| 133 | + peer = [ |
| 134 | + { |
| 135 | + name = "core-router-1" |
| 136 | + enable = true |
| 137 | + local_ip = "192.168.100.1" |
| 138 | + peer_ip = "192.168.101.1" |
| 139 | + peer_as = "65100" |
| 140 | + } |
| 141 | + ] |
| 142 | + } |
| 143 | + ] |
| 144 | + |
| 145 | + # BGP routing policies |
| 146 | + policy = { |
| 147 | + # Export rules: control what routes we advertise to peers |
| 148 | + export = { |
| 149 | + rules = [ |
| 150 | + { |
| 151 | + name = "advertise-local-networks" |
| 152 | + enable = true |
| 153 | + match = { |
| 154 | + # Match locally originated routes (empty AS path) |
| 155 | + as_path = { |
| 156 | + regex = "^$" |
| 157 | + } |
| 158 | + } |
| 159 | + action = { |
| 160 | + allow = { |
| 161 | + update = { |
| 162 | + origin = "igp" |
| 163 | + med = 100 |
| 164 | + local_preference = 150 |
| 165 | + # Prepend our AS twice for path manipulation |
| 166 | + as_path = { |
| 167 | + prepend = 2 |
| 168 | + } |
| 169 | + # Tag with community for route tracking |
| 170 | + community = { |
| 171 | + append = ["65100:1000", "65100:2000"] |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + }, |
| 177 | + { |
| 178 | + name = "block-private-as" |
| 179 | + enable = true |
| 180 | + match = { |
| 181 | + # Block routes with private AS numbers |
| 182 | + as_path = { |
| 183 | + regex = "^6500[0-9]" |
| 184 | + } |
| 185 | + } |
| 186 | + action = { |
| 187 | + deny = {} |
| 188 | + } |
| 189 | + } |
| 190 | + ] |
| 191 | + } |
| 192 | + |
| 193 | + # Import rules: control what routes we accept from peers |
| 194 | + import = { |
| 195 | + rules = [ |
| 196 | + { |
| 197 | + name = "prefer-customer-routes" |
| 198 | + enable = true |
| 199 | + match = { |
| 200 | + # Match customer routes by AS path and community |
| 201 | + as_path = { |
| 202 | + regex = ".*65200.*" |
| 203 | + } |
| 204 | + community = { |
| 205 | + regex = "65200:.*" |
| 206 | + } |
| 207 | + } |
| 208 | + action = { |
| 209 | + allow = { |
| 210 | + update = { |
| 211 | + # Increase local preference for customer routes |
| 212 | + local_preference = 200 |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + } |
| 217 | + ] |
| 218 | + } |
| 219 | + |
| 220 | + # Route aggregation for summarizing address blocks |
| 221 | + aggregation = { |
| 222 | + address = [ |
| 223 | + { |
| 224 | + name = "datacenter-summary" |
| 225 | + prefix = "10.0.0.0/8" |
| 226 | + enable = true |
| 227 | + summary = true |
| 228 | + aggregate_route_attributes = { |
| 229 | + origin = "incomplete" |
| 230 | + med = 50 |
| 231 | + as_path = { |
| 232 | + prepend = 1 |
| 233 | + } |
| 234 | + community = { |
| 235 | + argument = ["65100:3000", "65100:4000"] |
| 236 | + } |
| 237 | + } |
| 238 | + } |
| 239 | + ] |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + # Redistribute connected and static routes into BGP |
| 244 | + redist_rules = [ |
| 245 | + { |
| 246 | + name = "redist-connected" |
| 247 | + enable = true |
| 248 | + }, |
| 249 | + { |
| 250 | + name = "redist-static" |
| 251 | + enable = true |
| 252 | + } |
| 253 | + ] |
| 254 | + } |
| 255 | + } |
| 256 | +} |
0 commit comments