From dbf1435fd4474c045e167cc358be534d0bbe6fe7 Mon Sep 17 00:00:00 2001 From: Aaron Guise Date: Thu, 17 Mar 2022 12:09:58 +1300 Subject: [PATCH] Added in Terraform provisioner --- .drone.jsonnet | 19 +++++++++++--- terraform/drone-runners.tf | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 terraform/drone-runners.tf diff --git a/.drone.jsonnet b/.drone.jsonnet index dafc740..416fe6a 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -5,7 +5,6 @@ local distros = ['centos7', 'debian10', 'debian11']; - /* Configuration of DIND */ local docker_service() = { @@ -49,6 +48,7 @@ local test_distro(distribution) = local gen_pipeline(distro) = {kind: 'pipeline', type: 'docker', + node: {linodrone: true}, name: 'Test on %(distro)s' % { distro: distro }, steps: [test_distro(distro)], @@ -58,12 +58,25 @@ local gen_pipeline(distro) = [{ name: 'dockersock', temp: {}, - }, - ], + },], + depends_on: + ['runners'] }; // Generate the output [ + {kind: 'pipeline', + type: 'docker', + name: 'runners', + steps: + [{name: 'Provision with terraform', + image: 'hashicorp/terraform:1.1.7', + commands: ['cd terraform', + 'terraform init', + 'terraform plan', + 'terraform apply -auto-approve', + ]},] + }, gen_pipeline('centos7'), gen_pipeline('centos8'), gen_pipeline('rockylinux8'), diff --git a/terraform/drone-runners.tf b/terraform/drone-runners.tf new file mode 100644 index 0000000..a7ec096 --- /dev/null +++ b/terraform/drone-runners.tf @@ -0,0 +1,53 @@ +variable "drone_instances" { + description = "How many runner instances should there be?" + default = 3 +} +variable "root_pass" { + description = "Root password to set on the node" +} + +variable "linode_api_token" { + description = "Linode API Token" +} + +variable "ssh_pubkey" { + description = "SSH key to be allowed access by default" +} + +terraform { + required_providers { + linode = { + source = "linode/linode" + version = "1.16.0" + } + } +} + +provider "linode" { + token = var.linode_api_token +} + +resource "linode_instance" "terraform-drone" { + connection { + type = "ssh" + user = "root" + password = var.root_pass + host = self.ip_address + } + + count = var.drone_instances + image = "private/15818922" + label = "drone-runner-${count.index + 1}" + group = "docker" + tags = ["tag_Testing","docker"] + region = "ap-southeast" + type = "g6-nanode-1" + authorized_keys = [ var.ssh_pubkey ] + root_pass = var.root_pass + + provisioner "remote-exec" { + inline = [ + "yum upgrade -y && systemctl restart docker", + ] + } +} \ No newline at end of file