فهرست منبع

spin up instaces

Chris Mague 6 سال پیش
والد
کامیت
31e0ea9062
4فایلهای تغییر یافته به همراه88 افزوده شده و 0 حذف شده
  1. 16 0
      inputs.tf
  2. 39 0
      instances.tf
  3. 4 0
      test/main.tf
  4. 29 0
      variables.tf

+ 16 - 0
inputs.tf

@@ -0,0 +1,16 @@
+data "aws_ami" "re-ami" {
+  most_recent = true
+  name_regex  = "ubuntu-bionic-18.04-amd64-server"
+  # This is Canonical's ID
+  owners = ["099720109477"]
+
+  filter {
+    name   = "root-device-type"
+    values = ["ebs"]
+  }
+
+  filter {
+    name   = "virtualization-type"
+    values = ["hvm"]
+  }
+}

+ 39 - 0
instances.tf

@@ -0,0 +1,39 @@
+resource "aws_instance" "re" {
+  count                  = var.data-node-count
+  ami                    = data.aws_ami.re-ami.id
+  instance_type          = var.re-instance-type
+  availability_zone      = "${element(var.vpc-azs, count.index)}"
+  subnet_id              = "${element(var.vpc-subnets, count.index)}"
+  vpc_security_group_ids = [aws_security_group.re.id]
+  source_dest_check      = false
+  key_name               = "${var.vpc-name}"
+  tags                   = merge({ Name = "${var.vpc-name}-private-${element(var.vpc-azs, count.index)}" }, var.common-tags)
+
+}
+
+resource "aws_ebs_volume" "re-ephemeral" {
+  count             = var.data-node-count
+  availability_zone = "${element(var.vpc-azs, count.index)}"
+  size              = "${var.re-volume-size}"
+}
+
+resource "aws_volume_attachment" "re-ephemeral" {
+  count       = var.data-node-count
+  device_name = "/dev/sdh"
+  volume_id   = "${element(aws_ebs_volume.re-ephemeral.*.id, count.index)}"
+  instance_id = "${element(aws_instance.re.*.id, count.index)}"
+}
+
+resource "aws_ebs_volume" "re-persistant" {
+  count             = var.data-node-count
+  availability_zone = "${element(var.vpc-azs, count.index)}"
+  size              = "${var.re-volume-size}"
+}
+
+resource "aws_volume_attachment" "re-persistant" {
+  count       = var.data-node-count
+  device_name = "/dev/sdj"
+  volume_id   = "${element(aws_ebs_volume.re-persistant.*.id, count.index)}"
+  instance_id = "${element(aws_instance.re.*.id, count.index)}"
+}
+

+ 4 - 0
test/main.tf

@@ -8,8 +8,12 @@ module "mymodule" {
   profile  = "redislabs"
   region   = "us-east-1"
   open-nets = ["192.168.0.127/32"]
+  data-node-count = 3
   vpc-cidr = "10.0.0.0/16"
+  vpc-subnets = ["subnet-1", "subnet-2"]
   vpc-id = "vpc-12345678"
+  vpc-name = "myvpc"
+  vpc-azs = ["us-west-1a", "us-west-1b"]
   common-tags = {
     "Owner"   = "maguec"
     "Project" = "example"

+ 29 - 0
variables.tf

@@ -23,4 +23,33 @@ variable "vpc-cidr" {
 
 variable "vpc-id" {
   description = "The ID of the VPC"
+}
+
+variable "vpc-name" {
+  description = "The Name of the VPC"
+}
+
+variable "vpc-subnets" {
+  type        = list
+  description = "The list of subnets available to the VPC"
+}
+
+variable "vpc-azs" {
+  type        = list
+  description = "The ID of the VPC"
+}
+
+variable "data-node-count" {
+  description = "The number of RE data nodes"
+  default     = 3
+}
+
+variable "re-instance-type" {
+  description = "The size of instance to run"
+  default     = "m5a.2xlarge"
+}
+
+variable "re-volume-size" {
+  description = "The size of the two volumes to attach"
+  default     = "150"
 }