generated from equinix-labs/terraform-equinix-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
64 lines (49 loc) · 1.55 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
resource "equinix_metal_device" "runner" {
count = var.server_count
depends_on = [null_resource.delete_script]
hostname = "metal-runner-${count.index}"
plan = var.plan
metro = var.metro
operating_system = var.operating_system
billing_cycle = "hourly"
project_id = var.project_id
user_data = templatefile("${path.module}/templates/user-data.tftpl", {
personal_access_token = var.personal_access_token,
runner_scope = var.runner_scope,
}
)
tags = ["github-action-runner", "terraform"]
}
locals {
nonsensitive_pat = nonsensitive(var.personal_access_token)
}
resource "null_resource" "wait" {
count = var.server_count
triggers = {
id = equinix_metal_device.runner[count.index].id
hostname = equinix_metal_device.runner[count.index].hostname
}
provisioner "local-exec" {
quiet = true
command = "/bin/bash ${path.module}/scripts/wait-runner-online.sh ${var.runner_scope} ${self.triggers.hostname}"
environment = {
RUNNER_CFG_PAT = local.nonsensitive_pat
}
}
}
resource "null_resource" "delete_script" {
count = var.server_count
triggers = {
hostname = "metal-runner-${count.index}"
runner_scope = var.runner_scope
pat = var.personal_access_token
}
provisioner "local-exec" {
when = destroy
quiet = true
command = "/bin/bash ${path.module}/scripts/delete-runner.sh ${self.triggers.runner_scope} ${self.triggers.hostname}"
environment = {
RUNNER_CFG_PAT = self.triggers.pat
}
}
}