github.com/smithx10/nomad@v0.9.1-rc1/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 start nomad.service" 64 ] 65 66 connection { 67 user = "ubuntu" 68 private_key = "${module.keys.private_key_pem}" 69 } 70 } 71 } 72 73 resource "aws_instance" "client" { 74 ami = "${data.aws_ami.main.image_id}" 75 instance_type = "${var.instance_type}" 76 key_name = "${module.keys.key_name}" 77 vpc_security_group_ids = ["${aws_security_group.primary.id}"] 78 count = "${var.client_count}" 79 depends_on = ["aws_instance.server"] 80 81 # Instance tags 82 tags { 83 Name = "${local.random_name}-client-${count.index}" 84 ConsulAutoJoin = "auto-join" 85 } 86 87 ebs_block_device = { 88 device_name = "/dev/xvdd" 89 volume_type = "gp2" 90 volume_size = "50" 91 delete_on_termination = "true" 92 } 93 94 user_data = "${element(data.template_file.user_data_client.*.rendered, count.index)}" 95 iam_instance_profile = "${aws_iam_instance_profile.instance_profile.name}" 96 97 provisioner "file" { 98 content = "${file("${path.root}/configs/${var.indexed == false ? "client.hcl" : "indexed/client-${count.index}.hcl"}")}" 99 destination = "/tmp/client.hcl" 100 101 connection { 102 user = "ubuntu" 103 private_key = "${module.keys.private_key_pem}" 104 } 105 } 106 107 provisioner "remote-exec" { 108 inline = [ 109 "aws s3 cp s3://nomad-team-test-binary/builds-oss/${var.nomad_sha}.tar.gz nomad.tar.gz", 110 "sudo tar -zxvf nomad.tar.gz -C /usr/local/bin/", 111 "sudo cp /ops/shared/config/nomad.service /etc/systemd/system/nomad.service", 112 "sudo cp /tmp/client.hcl /etc/nomad.d/nomad.hcl", 113 "sudo chmod 0755 /usr/local/bin/nomad", 114 "sudo chown root:root /usr/local/bin/nomad", 115 "sudo systemctl start nomad.service" 116 ] 117 118 connection { 119 user = "ubuntu" 120 private_key = "${module.keys.private_key_pem}" 121 } 122 } 123 } 124