-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-edge-router.tf
43 lines (39 loc) · 1.72 KB
/
03-edge-router.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
data "template_file" "user_data" {
template = file("templates/user_data.py")
vars = {
private_subnets = jsonencode(var.private_subnets)
private_vlans = jsonencode(packet_vlan.private_vlans.*.vxlan)
public_subnets = jsonencode(var.public_subnets)
public_vlans = jsonencode(packet_vlan.public_vlans.*.vxlan)
public_cidrs = jsonencode(packet_reserved_ip_block.ip_blocks.*.cidr_notation)
domain_name = var.domain_name
}
}
resource "packet_device" "router" {
depends_on = [packet_project_ssh_key.ssh_pub_key]
hostname = var.router_hostname
plan = var.router_size
facilities = [var.facility]
operating_system = var.router_os
billing_cycle = var.billing_cycle
project_id = local.project_id
user_data = data.template_file.user_data.rendered
network_type = "hybrid"
}
resource "packet_port_vlan_attachment" "router_priv_vlan_attach" {
count = length(packet_vlan.private_vlans)
device_id = packet_device.router.id
port_name = "eth1"
vlan_vnid = jsonencode(element(packet_vlan.private_vlans.*.vxlan, count.index))
}
resource "packet_port_vlan_attachment" "router_pub_vlan_attach" {
count = length(packet_vlan.public_vlans)
device_id = packet_device.router.id
port_name = "eth1"
vlan_vnid = jsonencode(element(packet_vlan.public_vlans.*.vxlan, count.index))
}
resource "packet_ip_attachment" "block_assignment" {
count = length(packet_reserved_ip_block.ip_blocks)
device_id = packet_device.router.id
cidr_notation = substr(jsonencode(element(packet_reserved_ip_block.ip_blocks.*.cidr_notation, count.index)), 1, length(jsonencode(element(packet_reserved_ip_block.ip_blocks.*.cidr_notation, count.index))) - 2)
}