-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: introduce VLAN for private networking
Signed-off-by: Marques Johansson <[email protected]>
- Loading branch information
Showing
15 changed files
with
246 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## template: jinja | ||
#cloud-config | ||
package_update: true | ||
package_upgrade: true | ||
package_reboot_if_required: true | ||
write_files: | ||
- path: /etc/sysctl.d/10-ip-forwarding.conf | ||
content: | | ||
net.ipv4.ip_forward=1 | ||
- path: /etc/iptables/rules.v4 | ||
content: | | ||
# Generated by iptables-save v1.8.4 on Tue Aug 24 19:16:37 2021 | ||
*filter | ||
:INPUT ACCEPT [0:0] | ||
:FORWARD ACCEPT [0:0] | ||
:OUTPUT ACCEPT [0:0] | ||
COMMIT | ||
# Completed on Tue Aug 24 19:16:37 2021 | ||
# Generated by iptables-save v1.8.4 on Tue Aug 24 19:16:37 2021 | ||
*nat | ||
:PREROUTING ACCEPT [0:0] | ||
:INPUT ACCEPT [0:0] | ||
:OUTPUT ACCEPT [0:0] | ||
:POSTROUTING ACCEPT [0:0] | ||
-A POSTROUTING -o bond0 -j MASQUERADE | ||
COMMIT | ||
# Completed on Tue Aug 24 19:16:37 2021 | ||
- path: /etc/iptables/rules.v6 | ||
content: | | ||
# Generated by ip6tables-save v1.8.4 on Tue Aug 24 19:16:37 2021 | ||
*filter | ||
:INPUT ACCEPT [0:0] | ||
:FORWARD ACCEPT [0:0] | ||
:OUTPUT ACCEPT [0:0] | ||
COMMIT | ||
- path: /etc/network/interfaces | ||
append: true | ||
content: | | ||
|
||
auto bond0.${metal_vlan_id} | ||
iface bond0.${metal_vlan_id} inet static | ||
pre-up sleep 5 | ||
address ${address} | ||
netmask ${netmask} | ||
vlan-raw-device bond0 | ||
- path: /etc/dnsmasq.d/openshift.config | ||
append: true | ||
content: | | ||
bind-interfaces | ||
interface=bond0.${metal_vlan_id} | ||
dhcp-range=${host_dhcp_start},${host_dhcp_end},${lease_time} | ||
packages: | ||
- iptables | ||
- iptables-services | ||
- dnsmasq | ||
runcmd: | ||
- sysctl -p /etc/sysctl.d/10-ip-forwarding.conf | ||
- systemctl restart networking | ||
- systemctl restart dnsmasq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
locals { | ||
vlan_id = var.create_vlan ? element(equinix_metal_vlan.openshift[*].id, 0) : element(data.equinix_metal_vlan.openshift[*].id, 0) | ||
vxlan = var.create_vlan ? element(equinix_metal_vlan.openshift[*].vxlan, 0) : element(data.equinix_metal_vlan.openshift[*].vxlan, 0) | ||
vrf_id = var.create_vrf ? element(equinix_metal_vrf.openshift[*].id, 0) : element(data.equinix_metal_vrf.openshift[*].id, 0) | ||
} | ||
|
||
|
||
# This generates a random suffix to avoid VRF name | ||
# collisions when multiple clusters are deployed to | ||
# an existing Metal project | ||
resource "random_string" "vrf_name_suffix" { | ||
length = 5 | ||
special = false | ||
} | ||
|
||
|
||
resource "equinix_metal_vlan" "openshift" { | ||
count = var.create_vlan ? 1 : 0 | ||
project_id = var.project_id | ||
description = var.metal_vlan_description | ||
metro = var.metal_metro | ||
} | ||
|
||
|
||
data "equinix_metal_vlan" "openshift" { | ||
count = var.create_vlan ? 0 : 1 | ||
project_id = var.project_id | ||
vxlan = var.metal_vlan_id | ||
} | ||
|
||
resource "equinix_metal_vrf" "openshift" { | ||
count = var.create_vrf ? 1 : 0 | ||
description = "VRF with ASN 65000 and a pool of address space that includes 192.168.100.0/25" | ||
name = "openshift-vrf-${random_string.vrf_name_suffix.result}" | ||
metro = var.metal_metro | ||
local_asn = "65000" | ||
ip_ranges = [var.cluster_subnet] | ||
project_id = var.project_id | ||
} | ||
|
||
data "equinix_metal_vrf" "openshift" { | ||
count = var.create_vrf ? 0 : 1 | ||
vrf_id = var.vrf_id | ||
} | ||
|
||
resource "equinix_metal_reserved_ip_block" "openshift" { | ||
description = "Reserved IP block (${var.cluster_subnet}) taken from on of the ranges in the VRF's pool of address space." | ||
project_id = var.project_id | ||
metro = var.metal_metro | ||
type = "vrf" | ||
vrf_id = local.vrf_id | ||
cidr = split("/", var.cluster_subnet)[1] | ||
network = cidrhost(var.cluster_subnet, 0) | ||
} | ||
|
||
resource "equinix_metal_gateway" "gateway" { | ||
project_id = var.project_id | ||
vlan_id = local.vlan_id | ||
ip_reservation_id = equinix_metal_reserved_ip_block.openshift.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
output "vrf_id" { | ||
value = local.vrf_id | ||
} | ||
|
||
output "vlan_id" { | ||
value = local.vlan_id | ||
} | ||
|
||
output "reserved_ip_block_id" { | ||
value = equinix_metal_reserved_ip_block.openshift.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
variable "cluster_subnet" { default = "192.168.100.0/22" } | ||
variable "metal_metro" { default = "da" } | ||
variable "create_vrf" { default = true } | ||
variable "project_id" {} | ||
|
||
variable "create_vlan" { | ||
type = bool | ||
default = true | ||
description = "Whether to create a new VLAN for this project." | ||
} | ||
variable "metal_vlan_id" { | ||
type = number | ||
default = null | ||
description = "ID of the VLAN you wish to use." | ||
} | ||
|
||
variable "metal_vlan_description" { | ||
type = string | ||
default = "openshift-demo" | ||
description = "Description to add to created VLAN." | ||
} | ||
|
||
|
||
variable "vrf_id" { | ||
type = string | ||
default = null | ||
description = "ID of the VRF you wish to use." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
terraform { | ||
required_providers { | ||
equinix = { | ||
source = "equinix/equinix" | ||
version = "~> 1.14" | ||
} | ||
null = { | ||
source = "hashicorp/null" | ||
} | ||
} | ||
required_version = ">= 1.0.0" | ||
provider_meta "equinix" { | ||
module_name = "equinix-metal-openshift-on-baremetal/bastion" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters