Skip to content

Commit

Permalink
update terraform configuration to use metal_ports
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Dec 14, 2021
1 parent 1675656 commit 4e4decc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 51 deletions.
32 changes: 16 additions & 16 deletions deploy/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deploy/terraform/cloud-config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ write_files:
runcmd:
- cd /root/sandbox/compose && unzip /root/compose.zip
- cd /root/sandbox/compose && TINKERBELL_CLIENT_MAC=${WORKER_MAC} TINKERBELL_TEMPLATE_MANIFEST=/manifests/template/ubuntu-equinix-metal.yaml TINKERBELL_HARDWARE_MANIFEST=/manifests/hardware/hardware-equinix-metal.json docker-compose up -d
- cd /root/sandbox/compose && bash tls/trust.sh ${PROVISIONER_IP}
- cd /root/sandbox/compose && bash tls/trust.sh $(ip route get 1.2.3.4 | awk '{print $7}')
58 changes: 28 additions & 30 deletions deploy/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Configure the Packet Provider.
# Configure the Equinix Metal Provider.
terraform {
required_providers {
metal = {
source = "equinix/metal"
version = "3.1.0"
version = "3.2.0"
}
null = {
source = "hashicorp/null"
Expand All @@ -23,59 +23,58 @@ provider "metal" {
# Create a new VLAN in datacenter "ewr1"
resource "metal_vlan" "provisioning_vlan" {
description = "provisioning_vlan"
facility = var.facility
metro = var.metro
project_id = var.project_id
}

# Create a device and add it to tf_project_1
resource "metal_device" "tink_worker" {
hostname = "tink-worker"
plan = var.device_type
facilities = [var.facility]
metro = var.metro
operating_system = "custom_ipxe"
ipxe_script_url = "https://boot.netboot.xyz"
always_pxe = "true"
billing_cycle = "hourly"
project_id = var.project_id
}

resource "metal_device_network_type" "tink_worker_network_type" {
device_id = metal_device.tink_worker.id
type = "layer2-individual"
resource "metal_port" "tink_worker_bond0" {
port_id = [for p in metal_device.tink_worker.ports : p.id if p.name == "bond0"][0]
layer2 = true
bonded = false
# vlan_ids = [metal_vlan.provisioning_vlan.id]
# Can't do this: │ Error: vlan assignment batch could not be created: POST https://api.equinix.com/metal/v1/ports/b0bdf6d8-589e-4988-9000-9f49c97a54e1/vlan-assignments/batches: 422 Can't assign VLANs to port b0bdf6d8-589e-4988-9000-9f49c97a54e1, the port is configured for Layer 3 mode., Port b0bdf6d8-589e-4988-9000-9f49c97a54e1 cannot be assigned to VLANs., Bond disabled
}

# Attach VLAN to worker
resource "metal_port_vlan_attachment" "worker" {
depends_on = [metal_device_network_type.tink_worker_network_type]

device_id = metal_device.tink_worker.id
port_name = "eth0"
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
resource "metal_port" "tink_worker_eth0" {
depends_on = [metal_port.tink_worker_bond0]
port_id = [for p in metal_device.tink_worker.ports : p.id if p.name == "eth0"][0]
#layer2 = true
# TODO(displague) the terraform provider is not permitting this, perhaps a bug in the provider validation
# layer2 flag can be set only for bond ports
bonded = false
vlan_ids = [metal_vlan.provisioning_vlan.id]
// vxlan_ids = [1000]
}


# Create a device and add it to tf_project_1
resource "metal_device" "tink_provisioner" {
hostname = "tink-provisioner"
plan = var.device_type
facilities = [var.facility]
metro = var.metro
operating_system = "ubuntu_20_04"
billing_cycle = "hourly"
project_id = var.project_id
user_data = data.cloudinit_config.setup.rendered
}

resource "metal_device_network_type" "tink_provisioner_network_type" {
device_id = metal_device.tink_provisioner.id
type = "hybrid"
}

# Attach VLAN to provisioner
resource "metal_port_vlan_attachment" "provisioner" {
depends_on = [metal_device_network_type.tink_provisioner_network_type]
device_id = metal_device.tink_provisioner.id
port_name = "eth1"
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
# Provisioners eth1 (unbonded) is attached to the provisioning VLAN
resource "metal_port" "eth1" {
port_id = [for p in metal_device.tink_provisioner.ports : p.id if p.name == "eth1"][0]
bonded = false
vlan_ids = [metal_vlan.provisioning_vlan.id]
}

data "archive_file" "compose" {
Expand All @@ -85,7 +84,7 @@ data "archive_file" "compose" {
}

locals {
compose_zip = data.archive_file.compose.output_size > 0 ? "" : filebase64("${path.module}/compose.zip")
compose_zip = data.archive_file.compose.output_size > 0 ? filebase64("${path.module}/compose.zip") : ""
}

data "cloudinit_config" "setup" {
Expand All @@ -102,9 +101,8 @@ data "cloudinit_config" "setup" {
part {
content_type = "text/cloud-config"
content = templatefile("${path.module}/cloud-config.cfg", {
COMPOSE_ZIP = local.compose_zip
WORKER_MAC = metal_device.tink_worker.ports[1].mac
PROVISIONER_IP = metal_device.tink_provisioner.network[0].address
COMPOSE_ZIP = local.compose_zip
WORKER_MAC = metal_device.tink_worker.ports[1].mac
})
}
}
8 changes: 4 additions & 4 deletions deploy/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ variable "project_id" {
type = string
}

variable "facility" {
description = "Packet facility to provision in"
variable "metro" {
description = "Equinix Metal metr to provision in"
type = string
default = "sjc1"
default = "sv"
}

variable "device_type" {
Expand All @@ -30,4 +30,4 @@ variable "ssh_private_key" {
type = string
description = "ssh private key file to use"
default = "~/.ssh/id_rsa"
}
}

0 comments on commit 4e4decc

Please sign in to comment.