Before you start make sure you get digital Ocean API token and also add your ssh public key to Digital ocean settings.
Make sure you have no runner with the same name on your github repository. If so remove it.
Add the the following block to your terraform file
... provisioner "remote-exec" { inline = [ "export PATH=$PATH:/usr/bin", # install github runner "mkdir actions-runner && cd actions-runner", "curl -o actions-runner-linux-x64-2.310.2.tar.gz -L https://github.com/actions/runner/releases/download/v2.310.2/actions-runner-linux-x64-2.310.2.tar.gz", "tar xzf ./actions-runner-linux-x64-2.310.2.tar.gz", "sudo RUNNER_ALLOW_RUNASROOT=1 ./config.sh --url https://github.com/username/reponame --token ${var.github_token} --work /workdirectory --name www-1 --labels www-1 --unattended", "sudo ./svc.sh install", "sudo ./svc.sh start", "sudo ./svc.sh status" ] } ...
Don't forget to replace https://github.com/username/reponameyour with your Github repository and /workdirectory your working directory.
You will see a similar command when you go to Github.com -> your repository setting -> runners -> New self-hosted runner page.
Copy the generated token and from your terraform file directory run:
terraform plan -out=infra.out
when prompt for token just past it on the console
then run:
terraform apply -auto-approve "infra.out
Thats it, terraform will provision your droplet/machine/node with a runner. Please remember to delete the runner if it exists before provisioning. Alternatively you can store the runner name in a variable. Also, note that github token expires after sometime, so its better to generate the token when you're about to run the apply command.