Skip to content

Instantly share code, notes, and snippets.

@goldenprifti
Last active July 14, 2022 22:38
Show Gist options
  • Save goldenprifti/fec6dcf629c206cf8ebbcb3088848c80 to your computer and use it in GitHub Desktop.
Save goldenprifti/fec6dcf629c206cf8ebbcb3088848c80 to your computer and use it in GitHub Desktop.
terraform {
required_providers {
equinix = {
source = "equinix/equinix"
}
}
}
provider "equinix" {
auth_token = "TOKEN"
}
data "local_file" "private_key" {
filename = "/root/.ssh/id_rsa"
}
resource "equinix_metal_device" "host1" {
hostname = "host1"
plan = "c3.small.x86"
metro = "dc"
operating_system = "centos_7"
billing_cycle = "hourly"
project_id = "990a277d-dcf3-4131-887e-33eab49827ce"
connection {
type = "ssh"
user = "root"
private_key = data.local_file.private_key.content
host = self.access_public_ipv4
}
provisioner "remote-exec" {
inline = [
"echo -e 'DEVICE=bond0 \nNAME=bond0 \nBOOTPROTO=none \nONBOOT=yes \nUSERCTL=no \nTYPE=Bond \nBONDING_OPTS=mode=4 miimon=100 downdelay=200 updelay=200 \nDNS1=1.1.1.1 \nDNS2=8.8.8.8' > /etc/sysconfig/network-scripts/ifcfg-bond0",
"echo -e 'DEVICE=bond0.1001 \nONBOOT=yes \nBOOTPROTO=none \nIPADDR=147.75.50.67 \nNETMASK=255.255.255.248 \nGATEWAY=147.75.50.65 \nVLAN=yes' > /etc/sysconfig/network-scripts/ifcfg-bond0.1001",
"echo -e 'DEVICE=bond0.1002 \nONBOOT=yes \nBOOTPROTO=none \nIPADDR=192.168.10.11 \nNETMASK=255.255.255.0 \nVLAN=yes' > /etc/sysconfig/network-scripts/ifcfg-bond0.1002",
"echo -e '0.0.0.0/0 via 147.75.50.65 dev bond0.1001' > /etc/sysconfig/network-scripts/route-bond0.1001",
"rm -rf /etc/sysconfig/network-scripts/ifcfg-eth0",
"rm -rf /etc/sysconfig/network-scripts/ifcfg-bond0:0",
"rm -rf /etc/sysconfig/network-scripts/route-bond0",
"yum remove cloud-init -y",
"shutdown -r 1"
]
}
}
resource "equinix_metal_port" "l2_bond_port" {
port_id = [for p in equinix_metal_device.host1.ports : p.id if p.name == "bond0"][0]
layer2 = true
bonded = true
vxlan_ids = [1001,1002]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment