Tarantool development patches archive
 help / color / mirror / Atom feed
From: sergeyb@tarantool.org
To: tarantool-patches@dev.tarantool.org, avtikhon@tarantool.org,
	alexander.turenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 1/4] extra: add Terraform config files
Date: Wed, 16 Sep 2020 10:07:19 +0300	[thread overview]
Message-ID: <fb09542cc6ef89dcc98ae06c3edc787a7dee59ba.1600239621.git.sergeyb@tarantool.org> (raw)
In-Reply-To: <cover.1600239621.git.sergeyb@tarantool.org>

From: Sergey Bronnikov <sergeyb@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

  reply	other threads:[~2020-09-16  7:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16  7:07 [Tarantool-patches] [PATCH 0/4] Integrate Jepsen tests to CI sergeyb
2020-09-16  7:07 ` sergeyb [this message]
2020-09-18 14:20   ` [Tarantool-patches] [PATCH 1/4] extra: add Terraform config files Alexander V. Tikhonov
2020-09-16  7:07 ` [Tarantool-patches] [PATCH 2/4] cmake: add targets to run Jepsen tests sergeyb
2020-09-18 14:23   ` Alexander V. Tikhonov
2020-09-16  7:07 ` [Tarantool-patches] [PATCH 3/4] tools: add script " sergeyb
2020-09-18 14:32   ` Alexander V. Tikhonov
2020-09-16  7:07 ` [Tarantool-patches] [PATCH 4/4] ci: integrate Jepsen tests to GitLab CI sergeyb
2020-09-17  7:12   ` Alexander V. Tikhonov
2020-09-17 15:25     ` Alexander Turenko
2020-09-18 12:28       ` Sergey Bronnikov
2020-09-18 12:34         ` Alexander V. Tikhonov
2020-09-18 12:33     ` Sergey Bronnikov
2020-09-18 15:03 ` [Tarantool-patches] [PATCH 0/4] Integrate Jepsen tests to CI Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb09542cc6ef89dcc98ae06c3edc787a7dee59ba.1600239621.git.sergeyb@tarantool.org \
    --to=sergeyb@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=avtikhon@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/4] extra: add Terraform config files' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox