Skip to content

Commit 52067a1

Browse files
committed
update terraform configuration to use metal_ports
Signed-off-by: Marques Johansson <[email protected]>
1 parent e42dcb4 commit 52067a1

File tree

4 files changed

+49
-50
lines changed

4 files changed

+49
-50
lines changed

deploy/terraform/.terraform.lock.hcl

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/terraform/cloud-config.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ write_files:
99
runcmd:
1010
- cd /root/sandbox/compose && unzip /root/compose.zip
1111
- 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
12+

deploy/terraform/main.tf

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Configure the Packet Provider.
1+
# Configure the Equinix Metal Provider.
22
terraform {
33
required_providers {
44
metal = {
55
source = "equinix/metal"
6-
version = "3.1.0"
6+
version = "3.2.0"
77
}
88
null = {
99
source = "hashicorp/null"
@@ -23,59 +23,58 @@ provider "metal" {
2323
# Create a new VLAN in datacenter "ewr1"
2424
resource "metal_vlan" "provisioning_vlan" {
2525
description = "provisioning_vlan"
26-
facility = var.facility
26+
metro = var.metro
2727
project_id = var.project_id
2828
}
2929

3030
# Create a device and add it to tf_project_1
3131
resource "metal_device" "tink_worker" {
3232
hostname = "tink-worker"
3333
plan = var.device_type
34-
facilities = [var.facility]
34+
metro = var.metro
3535
operating_system = "custom_ipxe"
3636
ipxe_script_url = "https://boot.netboot.xyz"
3737
always_pxe = "true"
3838
billing_cycle = "hourly"
3939
project_id = var.project_id
4040
}
4141

42-
resource "metal_device_network_type" "tink_worker_network_type" {
43-
device_id = metal_device.tink_worker.id
44-
type = "layer2-individual"
42+
resource "metal_port" "tink_worker_bond0" {
43+
port_id = [for p in metal_device.tink_worker.ports : p.id if p.name == "bond0"][0]
44+
layer2 = true
45+
bonded = false
46+
# vlan_ids = [metal_vlan.provisioning_vlan.id]
47+
# 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
4548
}
4649

4750
# Attach VLAN to worker
48-
resource "metal_port_vlan_attachment" "worker" {
49-
depends_on = [metal_device_network_type.tink_worker_network_type]
50-
51-
device_id = metal_device.tink_worker.id
52-
port_name = "eth0"
53-
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
51+
resource "metal_port" "tink_worker_eth0" {
52+
depends_on = [metal_port.tink_worker_bond0]
53+
port_id = [for p in metal_device.tink_worker.ports : p.id if p.name == "eth0"][0]
54+
#layer2 = true
55+
# TODO(displague) the terraform provider is not permitting this, perhaps a bug in the provider validation
56+
# layer2 flag can be set only for bond ports
57+
bonded = false
58+
vlan_ids = [metal_vlan.provisioning_vlan.id]
59+
// vxlan_ids = [1000]
5460
}
5561

56-
5762
# Create a device and add it to tf_project_1
5863
resource "metal_device" "tink_provisioner" {
5964
hostname = "tink-provisioner"
6065
plan = var.device_type
61-
facilities = [var.facility]
66+
metro = var.metro
6267
operating_system = "ubuntu_20_04"
6368
billing_cycle = "hourly"
6469
project_id = var.project_id
6570
user_data = data.cloudinit_config.setup.rendered
6671
}
6772

68-
resource "metal_device_network_type" "tink_provisioner_network_type" {
69-
device_id = metal_device.tink_provisioner.id
70-
type = "hybrid"
71-
}
72-
73-
# Attach VLAN to provisioner
74-
resource "metal_port_vlan_attachment" "provisioner" {
75-
depends_on = [metal_device_network_type.tink_provisioner_network_type]
76-
device_id = metal_device.tink_provisioner.id
77-
port_name = "eth1"
78-
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
73+
# Provisioners eth1 (unbonded) is attached to the provisioning VLAN
74+
resource "metal_port" "eth1" {
75+
port_id = [for p in metal_device.tink_provisioner.ports : p.id if p.name == "eth1"][0]
76+
bonded = false
77+
vlan_ids = [metal_vlan.provisioning_vlan.id]
7978
}
8079

8180
data "archive_file" "compose" {
@@ -85,7 +84,7 @@ data "archive_file" "compose" {
8584
}
8685

8786
locals {
88-
compose_zip = data.archive_file.compose.output_size > 0 ? "" : filebase64("${path.module}/compose.zip")
87+
compose_zip = data.archive_file.compose.output_size > 0 ? filebase64("${path.module}/compose.zip") : ""
8988
}
9089

9190
data "cloudinit_config" "setup" {
@@ -102,9 +101,8 @@ data "cloudinit_config" "setup" {
102101
part {
103102
content_type = "text/cloud-config"
104103
content = templatefile("${path.module}/cloud-config.cfg", {
105-
COMPOSE_ZIP = local.compose_zip
106-
WORKER_MAC = metal_device.tink_worker.ports[1].mac
107-
PROVISIONER_IP = metal_device.tink_provisioner.network[0].address
104+
COMPOSE_ZIP = local.compose_zip
105+
WORKER_MAC = metal_device.tink_worker.ports[1].mac
108106
})
109107
}
110108
}

deploy/terraform/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ variable "project_id" {
88
type = string
99
}
1010

11-
variable "facility" {
12-
description = "Packet facility to provision in"
11+
variable "metro" {
12+
description = "Equinix Metal metr to provision in"
1313
type = string
14-
default = "sjc1"
14+
default = "sv"
1515
}
1616

1717
variable "device_type" {
@@ -30,4 +30,4 @@ variable "ssh_private_key" {
3030
type = string
3131
description = "ssh private key file to use"
3232
default = "~/.ssh/id_rsa"
33-
}
33+
}

0 commit comments

Comments
 (0)