Browse Source

add in testing instance

Chris Mague 5 years ago
parent
commit
118fce5406
4 changed files with 68 additions and 1 deletions
  1. 18 0
      inputs.tf
  2. 5 0
      maguec1.tfvars
  3. 38 0
      main.tf
  4. 7 1
      variables.tf

+ 18 - 0
inputs.tf

@@ -1 +1,19 @@
 data "aws_caller_identity" "current" {}
+
+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"]
+  }
+}
+

+ 5 - 0
maguec1.tfvars

@@ -4,3 +4,8 @@ open-nets = ["76.14.80.208/32"]
 vpc-azs   = ["us-west-1a", "us-west-1c"]
 vpc-cidr  = "10.161.0.0/16"
 vpc-name  = "maguec1"
+common-tags     = {
+  "Owner"       = "maguec"
+  "Project"     = "cp-redis"
+}
+

+ 38 - 0
main.tf

@@ -37,6 +37,44 @@ module "nodes" {
   }
 }
 
+# Start CP Redis Testernode
+
+resource "aws_instance" "re" {
+  ami                    = data.aws_ami.re-ami.id
+  instance_type          = "m5.4xlarge"
+  availability_zone      = "${element(var.vpc-azs, 1)}"
+  subnet_id              = "${element(module.vpc.subnets-public, 1)}"
+  vpc_security_group_ids = [module.nodes.re-security-group]
+  source_dest_check      = false
+  key_name               = var.vpc-name
+  tags                   = merge({ Name = "Tester-${var.vpc-name}-1" }, var.common-tags)
+
+}
+
+resource "aws_eip" "re-eip" {
+  vpc   = true
+  tags  = merge({ Name = "${var.vpc-name}-node-eip-1" }, var.common-tags)
+}
+
+resource "aws_eip_association" "re-eip-assoc" {
+  instance_id   = "${element(aws_instance.re.*.id, 1)}"
+  allocation_id = "${element(aws_eip.re-eip.*.id, 1)}"
+  depends_on    = ["aws_instance.re", "aws_eip.re-eip"]
+}
+
+
+resource "null_resource" "remote-config" {
+  provisioner "remote-exec" {
+    connection {
+      user        = "ubuntu"
+      host        = aws_eip.re-eip.public_ip
+      private_key = "${file("~/.ssh/${var.vpc-name}.pem")}"
+      agent       = true
+    }
+    inline = ["sudo apt update > /dev/null  && sudo apt install -y python python-pip > /dev/null"]
+  }
+  depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
+}
 
 
 output "node-ips" {

+ 7 - 1
variables.tf

@@ -18,4 +18,10 @@ variable "vpc-azs" {
 variable "open-nets" {
   type        = list
   description = "Networks that will have full access"
-}
+}
+
+variable "common-tags" {
+  type        = map(string)
+  description = "Tags that go everywhere"
+}
+