Skip to content

Commit a5aad7a

Browse files
committed
make terraform config reusable as a module
- fix terraform resource paths (use path.module) - use cloud-config (avoiding ssh provisioners) - use templatefile (template_file resource is deprecated) - update metal version Signed-off-by: Marques Johansson <[email protected]>
1 parent 41cc30f commit a5aad7a

File tree

4 files changed

+143
-24
lines changed

4 files changed

+143
-24
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

deploy/terraform/main.tf

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ resource "metal_device" "tink_provisioner" {
6262
operating_system = "ubuntu_20_04"
6363
billing_cycle = "hourly"
6464
project_id = var.project_id
65-
user_data = file("setup.sh")
65+
user_data = data.cloudinit_config.setup.rendered
6666
}
6767

6868
resource "metal_device_network_type" "tink_provisioner_network_type" {
@@ -78,30 +78,29 @@ resource "metal_port_vlan_attachment" "provisioner" {
7878
vlan_vnid = metal_vlan.provisioning_vlan.vxlan
7979
}
8080

81+
data "archive_file" "compose" {
82+
type = "zip"
83+
source_dir = "${path.module}/../compose"
84+
output_path = "${path.module}/compose.zip"
85+
}
8186

82-
83-
resource "null_resource" "setup" {
84-
connection {
85-
type = "ssh"
86-
user = "root"
87-
host = metal_device.tink_provisioner.network[0].address
88-
private_key = file("~/.ssh/id_rsa")
89-
}
90-
91-
# need to tar the compose directory because the 'provisioner "file"' does not preserve file permissions
92-
provisioner "local-exec" {
93-
command = "cd ../ && tar zcvf compose.tar.gz compose"
94-
}
95-
96-
provisioner "file" {
97-
source = "../compose.tar.gz"
98-
destination = "/root/compose.tar.gz"
87+
data "cloudinit_config" "setup" {
88+
depends_on = [
89+
data.archive_file.compose,
90+
// resource.null_resource.setup
91+
]
92+
gzip = false # not supported on Equinix Metal
93+
base64_encode = false # not supported on Equinix Metal
94+
95+
part {
96+
content_type = "text/x-shellscript"
97+
content = file("${path.module}/setup.sh")
9998
}
100-
101-
provisioner "remote-exec" {
102-
inline = [
103-
"cd /root && tar zxvf /root/compose.tar.gz -C /root/sandbox",
104-
"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"
105-
]
99+
part {
100+
content_type = "text/cloud-config"
101+
content = templatefile("${path.module}/cloud-config.cfg", {
102+
COMPOSE_ZIP = filebase64("${path.module}/compose.zip")
103+
WORKER_MAC = metal_device.tink_worker.ports[1].mac
104+
})
106105
}
107106
}

0 commit comments

Comments
 (0)