@@ -11,10 +11,15 @@ resource "hcloud_server" "github_runner" {
1111 type = " ssh"
1212 private_key = file (var. ssh_private_key )
1313 }
14-
1514 provisioner "file" {
1615 source = " scripts/remote/setup-runner.sh"
1716 destination = " /srv/setup-runner.sh"
17+
18+ }
19+
20+ provisioner "file" {
21+ source = " scripts/remote/gh-runner-cli"
22+ destination = " /srv/gh-runner-cli"
1823 }
1924
2025 provisioner "remote-exec" {
@@ -33,12 +38,27 @@ resource "hcloud_server" "github_runner" {
3338 " curl -o actions-runner-linux-x64-2.277.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.277.1/actions-runner-linux-x64-2.277.1.tar.gz" ,
3439 " tar xzf ./actions-runner-linux-x64-2.277.1.tar.gz" ,
3540 " adduser github-runner --disabled-login --gecos ''" ,
36- " chown -R github-runner. /home/github-runner/.ssh" ,
3741 " usermod -aG docker github-runner" ,
3842 " echo 'github-runner ALL=(ALL:ALL)NOPASSWD:ALL' > /etc/sudoers.d/github-runner" ,
3943 " chown -R github-runner /srv" ,
40- " chmod +x /srv/setup-runner.sh" ,
41- " su github-runner -c '/srv/setup-runner.sh ${ var . github_actions_provision_url } ${ var . github_actions_provision_token } ${ var . github_actions_runner_labels } ${ var . github_actions_runner_replace_existing } '"
44+ " chmod +x /srv/setup-runner.sh /srv/gh-runner-cli " ,
45+ " su github-runner -c '/srv/setup-runner.sh ${ var . github_authentication_user } ${ var . github_authentication_token } ${ var . github_repository_owner } ${ var . github_repository_name } ${ var . github_actions_runner_labels } ${ var . github_actions_runner_replace_existing } '"
4246 ]
4347 }
4448}
49+
50+ resource "null_resource" "deprovision" {
51+ triggers = {
52+ machine_names = join (" ," , tolist (hcloud_server. github_runner . * . name ))
53+ github_user = var.github_authentication_user
54+ github_user_token = var.github_authentication_token
55+ github_repo_name = var.github_repository_name
56+ github_repo_owner = var.github_repository_owner
57+ }
58+
59+ provisioner "local-exec" {
60+ when = destroy
61+ # command = "./scripts/remote/gh-runner-cli repo runner destroy-by-name --username ${self.triggers.github_user} --token ${self.triggers.github_user_token} --name ${self.triggers.github_repo_name} --owner ${self.triggers.github_repo_owner} --runner-name ${each.value.name}"
62+ command = " ./scripts/local/destroy_runner.sh ${ self . triggers . machine_names } ${ self . triggers . github_user } ${ self . triggers . github_user_token } ${ self . triggers . github_repo_name } ${ self . triggers . github_repo_owner } "
63+ }
64+ }
0 commit comments