github.com/bigcommerce/nomad@v0.9.3-bc/e2e/terraform/compute.tf (about)

     1  data "template_file" "user_data_server" {
     2    template = "${file("${path.root}/user-data-server.sh")}"
     3  
     4    vars {
     5      server_count = "${var.server_count}"
     6      region       = "${var.region}"
     7      retry_join   = "${var.retry_join}"
     8    }
     9  }
    10  
    11  data "template_file" "user_data_client" {
    12    template = "${file("${path.root}/user-data-client.sh")}"
    13    count    = "${var.client_count}"
    14  
    15    vars {
    16      region     = "${var.region}"
    17      retry_join = "${var.retry_join}"
    18    }
    19  }
    20  
    21  data "template_file" "nomad_client_config" {
    22    template = "${file("${path.root}/configs/client.hcl")}"
    23  }
    24  
    25  data "template_file" "nomad_server_config" {
    26    template = "}"
    27  }
    28  
    29  resource "aws_instance" "server" {
    30    ami                    = "${data.aws_ami.main.image_id}"
    31    instance_type          = "${var.instance_type}"
    32    key_name               = "${module.keys.key_name}"
    33    vpc_security_group_ids = ["${aws_security_group.primary.id}"]
    34    count                  = "${var.server_count}"
    35  
    36    # Instance tags
    37    tags {
    38      Name           = "${local.random_name}-server-${count.index}"
    39      ConsulAutoJoin = "auto-join"
    40    }
    41  
    42    user_data            = "${data.template_file.user_data_server.rendered}"
    43    iam_instance_profile = "${aws_iam_instance_profile.instance_profile.name}"
    44  
    45    provisioner "file" {
    46      content     = "${file("${path.root}/configs/${var.indexed == false ? "server.hcl" : "indexed/server-${count.index}.hcl"}")}"
    47      destination = "/tmp/server.hcl"
    48  
    49      connection {
    50        user        = "ubuntu"
    51        private_key = "${module.keys.private_key_pem}"
    52      }
    53    }
    54  
    55    provisioner "remote-exec" {
    56      inline = [
    57        "aws s3 cp s3://nomad-team-test-binary/builds-oss/${var.nomad_sha}.tar.gz nomad.tar.gz",
    58        "sudo cp /ops/shared/config/nomad.service /etc/systemd/system/nomad.service",
    59        "sudo tar -zxvf nomad.tar.gz -C /usr/local/bin/",
    60        "sudo cp /tmp/server.hcl /etc/nomad.d/nomad.hcl",
    61        "sudo chmod 0755 /usr/local/bin/nomad",
    62        "sudo chown root:root /usr/local/bin/nomad",
    63        "sudo systemctl enable nomad.service",
    64        "sudo systemctl start nomad.service"
    65      ]
    66  
    67      connection {
    68        user        = "ubuntu"
    69        private_key = "${module.keys.private_key_pem}"
    70      }
    71    }
    72  }
    73  
    74  resource "aws_instance" "client" {
    75    ami                    = "${data.aws_ami.main.image_id}"
    76    instance_type          = "${var.instance_type}"
    77    key_name               = "${module.keys.key_name}"
    78    vpc_security_group_ids = ["${aws_security_group.primary.id}"]
    79    count                  = "${var.client_count}"
    80    depends_on             = ["aws_instance.server"]
    81  
    82    # Instance tags
    83    tags {
    84      Name           = "${local.random_name}-client-${count.index}"
    85      ConsulAutoJoin = "auto-join"
    86    }
    87  
    88    ebs_block_device =  {
    89      device_name                 = "/dev/xvdd"
    90      volume_type                 = "gp2"
    91      volume_size                 = "50"
    92      delete_on_termination       = "true"
    93    }
    94  
    95    user_data            = "${element(data.template_file.user_data_client.*.rendered, count.index)}"
    96    iam_instance_profile = "${aws_iam_instance_profile.instance_profile.name}"
    97  
    98    provisioner "file" {
    99      content     = "${file("${path.root}/configs/${var.indexed == false ? "client.hcl" : "indexed/client-${count.index}.hcl"}")}"
   100      destination = "/tmp/client.hcl"
   101  
   102      connection {
   103        user        = "ubuntu"
   104        private_key = "${module.keys.private_key_pem}"
   105      }
   106    }
   107  
   108    provisioner "remote-exec" {
   109      inline = [
   110        "aws s3 cp s3://nomad-team-test-binary/builds-oss/${var.nomad_sha}.tar.gz nomad.tar.gz",
   111        "sudo tar -zxvf nomad.tar.gz -C /usr/local/bin/",
   112        "sudo cp /ops/shared/config/nomad.service /etc/systemd/system/nomad.service",
   113        "sudo cp /tmp/client.hcl /etc/nomad.d/nomad.hcl",
   114        "sudo chmod 0755 /usr/local/bin/nomad",
   115        "sudo chown root:root /usr/local/bin/nomad",
   116  			"sudo systemctl enable nomad.service",
   117        "sudo systemctl start nomad.service"
   118      ]
   119  
   120      connection {
   121        user        = "ubuntu"
   122        private_key = "${module.keys.private_key_pem}"
   123      }
   124    }
   125  }
   126