[Tarantool-patches] [PATCH 1/4] extra: add Terraform config files

sergeyb at tarantool.org sergeyb at tarantool.org
Wed Sep 16 10:07:19 MSK 2020


From: Sergey Bronnikov <sergeyb at tarantool.org>

For testing Tarantool with Jepsen we use virtual machines as they provides
better resource isolation in comparison to containers. Jepsen tests may need a
single instance or a set of instances for testing cluster.  To setup virtual
machines we use Terraform [1]. Patch adds a set of configuration files for
Terraform that can create required number of virtual machines in MCS and output
IP addresses to stdout.

Terraform needs some parameters before run. They are:

- id, identificator of a test stand that should be specific for this run, id
also is a part of virtual machine name
- keypair_name, name of keypair used in a cloud, public SSH key of that key pair
will be placed to virtual machine
- instance_count, number of virtual machines in a test stand
- ssh_key, SSH private key, used to access to a virtual machine
- user_name
- password
- tenant_id
- user_domain_id

These parameters can be passed via enviroment variables with TF_VAR_ prefix
(like TF_VAR_id) or via command-line parameters.

To demonstrate full lifecycle of a test stand with Terraform one needs to
perform these commands:

terraform init extra/tf
terraform apply extra/tf
terraform output instance_names
terraform output instance_ips
terraform destroy extra/tf

1. https://www.terraform.io/

Part of #5277
---
 extra/tf/main.tf     | 43 ++++++++++++++++++++++++++++++++++++++
 extra/tf/outputs.tf  | 10 +++++++++
 extra/tf/provider.tf | 49 ++++++++++++++++++++++++++++++++++++++++++++
 extra/tf/versions.tf |  8 ++++++++
 4 files changed, 110 insertions(+)
 create mode 100644 extra/tf/main.tf
 create mode 100644 extra/tf/outputs.tf
 create mode 100644 extra/tf/provider.tf
 create mode 100644 extra/tf/versions.tf

diff --git a/extra/tf/main.tf b/extra/tf/main.tf
new file mode 100644
index 000000000..0b760884e
--- /dev/null
+++ b/extra/tf/main.tf
@@ -0,0 +1,43 @@
+resource "openstack_compute_instance_v2" "instance" {
+  count = var.instance_count
+
+  name = "tarantool_testing-${count.index + 1}-${var.id}"
+
+  image_name = "Ubuntu-18.04-202003"
+
+  image_id = "3f03b393-d45b-455d-bdf5-0ac4399ecf42"
+
+  flavor_name = "Basic-1-2-20"
+
+  key_pair = var.keypair_name
+
+  config_drive = true
+
+  availability_zone = "DP1"
+
+  security_groups = [
+    "default",
+    "allow-ssh",
+    "allow-tarantool"
+  ]
+
+  network {
+    name = "ext-net"
+  }
+
+  provisioner "remote-exec" {
+    inline = [
+      "sudo hostnamectl set-hostname n${count.index + 1}",
+      "sudo apt-get update"
+    ]
+  }
+
+  connection {
+    host = self.access_ip_v4
+    type = "ssh"
+    user = "ubuntu"
+    timeout = "5m"
+    agent = true
+    private_key = file(var.ssh_key_path)
+  }
+}
diff --git a/extra/tf/outputs.tf b/extra/tf/outputs.tf
new file mode 100644
index 000000000..5690d6b0d
--- /dev/null
+++ b/extra/tf/outputs.tf
@@ -0,0 +1,10 @@
+output "instance_names" {
+  description = "List of names assigned to the instances."
+  value = openstack_compute_instance_v2.instance.*.name
+}
+
+output "instance_ips" {
+  description = "List of public IP addresses assigned to the instances."
+  value = openstack_compute_instance_v2.instance.*.access_ip_v4
+  sensitive = true
+}
diff --git a/extra/tf/provider.tf b/extra/tf/provider.tf
new file mode 100644
index 000000000..cd9488ce5
--- /dev/null
+++ b/extra/tf/provider.tf
@@ -0,0 +1,49 @@
+variable "user_name" {
+  type = string
+}
+
+variable "password" {
+  type = string
+}
+
+variable "tenant_id" {
+  type = string
+}
+
+variable "user_domain_id" {
+  type = string
+}
+
+variable "keypair_name" {
+  type = string
+}
+
+variable "ssh_key_path" {
+  type = string
+}
+
+variable "instance_count" {
+  type = number
+  default = 1
+  description = "Number of instances."
+
+  validation {
+    condition = var.instance_count > 0
+    error_message = "The instance_count value must be greater than zero."
+  }
+}
+
+variable "id" {
+  type = string
+  default = null
+}
+
+provider "openstack" {
+  user_name = var.user_name
+  password = var.password
+  tenant_id = var.tenant_id
+  user_domain_id = var.user_domain_id
+  auth_url = "https://infra.mail.ru/identity/v3/"
+  region = "RegionOne"
+  use_octavia = true
+}
diff --git a/extra/tf/versions.tf b/extra/tf/versions.tf
new file mode 100644
index 000000000..5af3d608b
--- /dev/null
+++ b/extra/tf/versions.tf
@@ -0,0 +1,8 @@
+terraform {
+  required_providers {
+    openstack = {
+      source = "terraform-providers/openstack"
+    }
+  }
+  required_version = ">= 0.13"
+}
-- 
2.25.1



More information about the Tarantool-patches mailing list