diff --git a/terraform/triton/main.tf.tpl b/terraform/triton/main.tf.tpl new file mode 100644 index 0000000..8235860 --- /dev/null +++ b/terraform/triton/main.tf.tpl @@ -0,0 +1,46 @@ +terraform { + required_providers { + triton = { + source = "joyent/triton" + version = "0.8.2" + } + } +} + +provider "triton" { + account = "username" + key_id = "key:id" + url = "https://eu-ro-1.api.spearhead.cloud" + key_material = "/path/to/id_rsa" + insecure_skip_tls_verify = false +} + +resource "triton_machine" "internal_resource_name" { + count = var.instance_count + name = "linux-${count.index + 1}" + package = "standard-2cpu-4ram-100disk" + image = "b70d5484-5168-4ecb-8127-0a0c59c1d906" + + provisioner "file" { + source = "scripts/setup.sh" + destination = "/var/tmp/setup.sh" + } + + provisioner "remote-exec" { + inline = [ + "bash /var/tmp/setup.sh", + ] + } + + connection { + type = "ssh" + host = self.primaryip + user = "ubuntu" + } + + cns { + services = ["${var.service_name}"] + } + +} + diff --git a/terraform/triton/scripts/setup.sh b/terraform/triton/scripts/setup.sh new file mode 100644 index 0000000..610a336 --- /dev/null +++ b/terraform/triton/scripts/setup.sh @@ -0,0 +1,18 @@ +#!/usr/bin/bash + +# add things youd like to do after provisioning here + +# my_ip=`ip addr show net0 | grep -Po 'inet \K[\d.]+'` +# user_password=`openssl rand -base64 16` +# user="linux" +# sudo useradd -m -s /bin/bash -G sudo linux +# echo "linux:${user_password}" | sudo chpasswd + +# sudo sed -i 's/\PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config +# sudo sed -i 's/\ChallengeResponseAuthentication yes/ChallengeResponseAuthentication no/g' /etc/ssh/sshd_config +# sudo systemctl reload sshd + +# echo "Linux password: ${user_password}" >> /var/tmp/.setup +# echo "IP: ${my_ip}" >> /var/tmp/.setup +# cat /var/tmp/.setup + diff --git a/terraform/triton/variables.tf.tpl b/terraform/triton/variables.tf.tpl new file mode 100644 index 0000000..36ca005 --- /dev/null +++ b/terraform/triton/variables.tf.tpl @@ -0,0 +1,11 @@ +variable "instance_count" { + description = "Number of triton instances to create" + type = number + default = 8 +} + +variable "service_name" { + type = string + description = "The name of the service in CNS." + default = "somename" +}