Skip to content

Commit c21d11e

Browse files
authored
Merge pull request tinkerbell#96 from displague/terraform-paths
fix terraform resource paths, use templatefile, update metal version
2 parents f355537 + 4a7c2b3 commit c21d11e

File tree

6 files changed

+175
-54
lines changed

6 files changed

+175
-54
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
.terraform*
4+
5+
# .tfstate files
6+
*.tfstate
7+
*.tfstate.*
8+
9+
!.terraform.lock.hcl
110
envrc
211
out
312
!deploy/.env
@@ -9,3 +18,4 @@ deploy/compose/state/webroot/workflow/*
918
deploy/compose/state/webroot/*.gz
1019
workflow_id.txt
1120
compose.tar.gz
21+
compose.zip

deploy/terraform/.terraform.lock.hcl

Lines changed: 99 additions & 0 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
packages:
2+
- unzip
3+
4+
write_files:
5+
- encoding: b64
6+
content: ${COMPOSE_ZIP}
7+
path: /root/compose.zip
8+
9+
runcmd:
10+
- cd /root/sandbox/compose && unzip /root/compose.zip
11+
- 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: 48 additions & 48 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,86 +23,86 @@ 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
65-
user_data = file("setup.sh")
70+
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"
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]
7178
}
7279

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
80+
data "archive_file" "compose" {
81+
type = "zip"
82+
source_dir = "${path.module}/../compose"
83+
output_path = "${path.module}/compose.zip"
7984
}
8085

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

90+
data "cloudinit_config" "setup" {
91+
depends_on = [
92+
data.archive_file.compose,
93+
]
94+
gzip = false # not supported on Equinix Metal
95+
base64_encode = false # not supported on Equinix Metal
8296

83-
resource "null_resource" "setup" {
84-
connection {
85-
type = "ssh"
86-
user = "root"
87-
host = metal_device.tink_provisioner.network[0].address
88-
agent = var.use_ssh_agent
89-
private_key = var.use_ssh_agent ? null : file(var.ssh_private_key)
90-
}
91-
92-
# need to tar the compose directory because the 'provisioner "file"' does not preserve file permissions
93-
provisioner "local-exec" {
94-
command = "cd ../ && tar zcvf compose.tar.gz compose"
95-
}
96-
97-
provisioner "file" {
98-
source = "../compose.tar.gz"
99-
destination = "/root/compose.tar.gz"
97+
part {
98+
content_type = "text/x-shellscript"
99+
content = file("${path.module}/setup.sh")
100100
}
101-
102-
provisioner "remote-exec" {
103-
inline = [
104-
"cd /root && tar zxvf /root/compose.tar.gz -C /root/sandbox",
105-
"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",
106-
]
101+
part {
102+
content_type = "text/cloud-config"
103+
content = templatefile("${path.module}/cloud-config.cfg", {
104+
COMPOSE_ZIP = local.compose_zip
105+
WORKER_MAC = metal_device.tink_worker.ports[1].mac
106+
})
107107
}
108108
}

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 metro 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+
}

docs/quickstarts/TERRAFORMEM.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ This option will also show you how to create a machine to provision.
4242
Or if you have the [Equinix Metal CLI](https://github.com/equinix/metal-cli) installed run the following:
4343
4444
```bash
45-
metal device reboot -i $(terraform show -json | jq -r '.values.root_module.resources[1].values.id')
45+
metal device reboot -i $(terraform show -json | jq -r '.values.root_module.resources[3].values.id')
4646
```
4747
4848
5. Watch the provision complete
@@ -94,7 +94,7 @@ This option will also show you how to create a machine to provision.
9494
Now reboot the `tink-worker` via the [Equinix Metal Web UI](https://console.equinix.com), or if you have the [Equinix Metal CLI](https://github.com/equinix/metal-cli) installed run the following:
9595
9696
```bash
97-
metal device reboot -i $(terraform show -json | jq -r '.values.root_module.resources[1].values.id')
97+
metal device reboot -i $(terraform show -json | jq -r '.values.root_module.resources[3].values.id')
9898
```
9999
100100
7. Login to the machine

0 commit comments

Comments
 (0)