2020-08-20 11:53:27 +00:00
|
|
|
# Configure the Packet Provider.
|
2020-09-10 14:37:32 +00:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
2021-02-04 19:49:28 +00:00
|
|
|
metal = {
|
|
|
|
source = "equinix/metal"
|
2021-08-19 16:46:16 +00:00
|
|
|
version = "3.1.0"
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
|
|
|
null = {
|
2021-01-12 06:58:06 +00:00
|
|
|
source = "hashicorp/null"
|
2021-01-12 06:40:17 +00:00
|
|
|
version = "~> 2.1.2"
|
|
|
|
}
|
|
|
|
template = {
|
2021-01-12 06:58:06 +00:00
|
|
|
source = "hashicorp/template"
|
2021-01-12 06:40:17 +00:00
|
|
|
version = "~> 2.1.2"
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:49:28 +00:00
|
|
|
provider "metal" {
|
|
|
|
auth_token = var.metal_api_token
|
2020-08-20 11:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create a new VLAN in datacenter "ewr1"
|
2021-02-04 19:49:28 +00:00
|
|
|
resource "metal_vlan" "provisioning_vlan" {
|
2020-09-10 14:37:32 +00:00
|
|
|
description = "provisioning_vlan"
|
2020-08-20 11:53:27 +00:00
|
|
|
facility = var.facility
|
|
|
|
project_id = var.project_id
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a device and add it to tf_project_1
|
2021-08-19 16:46:16 +00:00
|
|
|
resource "metal_device" "tink_worker" {
|
|
|
|
hostname = "tink-worker"
|
2020-08-20 11:53:27 +00:00
|
|
|
plan = var.device_type
|
|
|
|
facilities = [var.facility]
|
2021-08-19 16:46:16 +00:00
|
|
|
operating_system = "custom_ipxe"
|
|
|
|
ipxe_script_url = "https://boot.netboot.xyz"
|
|
|
|
always_pxe = "true"
|
2020-08-20 11:53:27 +00:00
|
|
|
billing_cycle = "hourly"
|
|
|
|
project_id = var.project_id
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 16:46:16 +00:00
|
|
|
resource "metal_device_network_type" "tink_worker_network_type" {
|
|
|
|
device_id = metal_device.tink_worker.id
|
|
|
|
type = "layer2-individual"
|
|
|
|
}
|
2020-09-10 14:37:32 +00:00
|
|
|
|
2021-08-19 16:46:16 +00:00
|
|
|
# Attach VLAN to worker
|
|
|
|
resource "metal_port_vlan_attachment" "worker" {
|
|
|
|
depends_on = [metal_device_network_type.tink_worker_network_type]
|
2021-01-22 08:35:16 +00:00
|
|
|
|
2021-08-19 16:46:16 +00:00
|
|
|
device_id = metal_device.tink_worker.id
|
|
|
|
port_name = "eth0"
|
|
|
|
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
|
2020-08-20 11:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Create a device and add it to tf_project_1
|
2021-08-19 16:46:16 +00:00
|
|
|
resource "metal_device" "tink_provisioner" {
|
|
|
|
hostname = "tink-provisioner"
|
2020-08-20 11:53:27 +00:00
|
|
|
plan = var.device_type
|
|
|
|
facilities = [var.facility]
|
2021-08-19 16:46:16 +00:00
|
|
|
operating_system = "ubuntu_20_04"
|
2020-08-20 11:53:27 +00:00
|
|
|
billing_cycle = "hourly"
|
|
|
|
project_id = var.project_id
|
2021-08-19 16:46:16 +00:00
|
|
|
user_data = file("setup.sh")
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 16:46:16 +00:00
|
|
|
resource "metal_device_network_type" "tink_provisioner_network_type" {
|
|
|
|
device_id = metal_device.tink_provisioner.id
|
|
|
|
type = "hybrid"
|
2020-08-20 11:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Attach VLAN to provisioner
|
2021-02-04 19:49:28 +00:00
|
|
|
resource "metal_port_vlan_attachment" "provisioner" {
|
|
|
|
depends_on = [metal_device_network_type.tink_provisioner_network_type]
|
|
|
|
device_id = metal_device.tink_provisioner.id
|
2020-09-10 14:37:32 +00:00
|
|
|
port_name = "eth1"
|
2021-02-04 19:49:28 +00:00
|
|
|
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
|
2020-08-20 11:53:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 14:37:32 +00:00
|
|
|
|
2020-08-20 11:53:27 +00:00
|
|
|
|
2021-08-19 16:46:16 +00:00
|
|
|
resource "null_resource" "setup" {
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
|
|
|
user = "root"
|
|
|
|
host = metal_device.tink_provisioner.network[0].address
|
|
|
|
private_key = file("~/.ssh/id_rsa")
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 16:46:16 +00:00
|
|
|
# need to tar the compose directory because the 'provisioner "file"' does not preserve file permissions
|
|
|
|
provisioner "local-exec" {
|
|
|
|
command = "cd ../ && tar zcvf compose.tar.gz compose"
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
2020-08-20 11:53:27 +00:00
|
|
|
|
2020-09-10 14:37:32 +00:00
|
|
|
provisioner "file" {
|
2021-08-19 16:46:16 +00:00
|
|
|
source = "../compose.tar.gz"
|
|
|
|
destination = "/root/compose.tar.gz"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"cd /root && tar zxvf /root/compose.tar.gz -C /root/sandbox",
|
|
|
|
"cd /root/sandbox/compose && TINKERBELL_CLIENT_MAC=${metal_device.tink_worker.ports[1].mac} TINKERBELL_TEMPLATE_MANIFEST=/manifests/template/ubuntu-equinix-metal.yaml TINKERBELL_HARDWARE_MANIFEST=/manifests/hardware/hardware-equinix-metal.json docker-compose up -d"
|
|
|
|
]
|
2020-09-10 14:37:32 +00:00
|
|
|
}
|
2020-08-20 11:53:27 +00:00
|
|
|
}
|