Chris Mague 3 роки тому
батько
коміт
b3f28db497
3 змінених файлів з 36 додано та 1 видалено
  1. 7 1
      main.tf
  2. 4 0
      outputs.tf
  3. 25 0
      testernode.tf

+ 7 - 1
main.tf

@@ -19,5 +19,11 @@ locals {
 
 
 locals {
-  ssh_key= (var.ssh-key == "" ? var.vpc-name : replace(var.ssh-key, ".pem", ""))
+  ssh_key = (var.ssh-key == "" ? var.vpc-name : replace(var.ssh-key, ".pem", ""))
+}
+
+
+# if the tester-node-type is set add a tester node
+locals {
+  tester_count = (var.tester-node-type == "" ? 0 : 1)
 }

+ 4 - 0
outputs.tf

@@ -13,3 +13,7 @@ output "node-internal-ips" {
 output "node-ids" {
   value = aws_instance.re[*].id
 }
+
+output "tester-ips" {
+  value = aws_eip.tester-eip[*].public_ip
+}

+ 25 - 0
testernode.tf

@@ -0,0 +1,25 @@
+resource "aws_instance" "tester" {
+  count                  = local.tester_count
+  ami                    = data.aws_ami.re-ami.id
+  instance_type          = var.tester-node-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               = local.ssh_key
+  tags                   = merge({ Name = "RedisEnterprise-${var.vpc-name}-${count.index}" }, var.common-tags)
+
+}
+
+resource "aws_eip" "tester-eip" {
+  vpc   = true
+  count = local.tester_count
+  tags  = merge({ Name = "${var.vpc-name}-node-eip-${count.index}" }, var.common-tags)
+}
+
+resource "aws_eip_association" "tester-eip-assoc" {
+  count         = local.tester_count
+  instance_id   = element(aws_instance.tester.*.id, count.index)
+  allocation_id = element(aws_eip.tester-eip.*.id, count.index)
+  depends_on    = [aws_instance.tester, aws_eip.tester-eip]
+}