2018-12-17 17:40:09 +00:00
|
|
|
resource "aws_instance" "server" {
|
2019-10-14 15:27:08 +00:00
|
|
|
ami = data.aws_ami.main.image_id
|
|
|
|
instance_type = var.instance_type
|
|
|
|
key_name = module.keys.key_name
|
|
|
|
vpc_security_group_ids = [aws_security_group.primary.id]
|
|
|
|
count = var.server_count
|
2018-12-17 17:40:09 +00:00
|
|
|
|
|
|
|
# Instance tags
|
2019-10-14 15:27:08 +00:00
|
|
|
tags = {
|
2018-12-17 17:40:09 +00:00
|
|
|
Name = "${local.random_name}-server-${count.index}"
|
|
|
|
ConsulAutoJoin = "auto-join"
|
2019-10-14 15:27:08 +00:00
|
|
|
SHA = var.nomad_sha
|
|
|
|
User = data.aws_caller_identity.current.arn
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 15:27:08 +00:00
|
|
|
iam_instance_profile = aws_iam_instance_profile.instance_profile.name
|
2018-12-17 17:40:09 +00:00
|
|
|
|
2019-10-25 12:08:24 +00:00
|
|
|
# copy up all provisioning scripts and configs
|
|
|
|
provisioner "file" {
|
|
|
|
source = "shared/"
|
|
|
|
destination = "/ops/shared"
|
|
|
|
|
|
|
|
connection {
|
|
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
|
|
type = "ssh"
|
|
|
|
user = "ubuntu"
|
|
|
|
private_key = module.keys.private_key_pem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 17:40:09 +00:00
|
|
|
provisioner "file" {
|
2019-10-14 15:27:08 +00:00
|
|
|
content = file(
|
|
|
|
"${path.root}/configs/${var.indexed == false ? "server.hcl" : "indexed/server-${count.index}.hcl"}",
|
|
|
|
)
|
2018-12-17 17:40:09 +00:00
|
|
|
destination = "/tmp/server.hcl"
|
|
|
|
|
|
|
|
connection {
|
2019-10-14 15:27:08 +00:00
|
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
|
|
type = "ssh"
|
2018-12-17 17:40:09 +00:00
|
|
|
user = "ubuntu"
|
2019-10-14 15:27:08 +00:00
|
|
|
private_key = module.keys.private_key_pem
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-25 12:08:24 +00:00
|
|
|
|
2018-12-17 17:40:09 +00:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
2019-10-25 12:08:24 +00:00
|
|
|
"chmod +x /ops/shared/config/provision-server.sh",
|
|
|
|
"/ops/shared/config/provision-server.sh aws ${var.server_count} '${var.retry_join}' ${var.nomad_sha}",
|
2018-12-17 17:40:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
connection {
|
2019-10-14 15:27:08 +00:00
|
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
|
|
type = "ssh"
|
2018-12-17 17:40:09 +00:00
|
|
|
user = "ubuntu"
|
2019-10-14 15:27:08 +00:00
|
|
|
private_key = module.keys.private_key_pem
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_instance" "client" {
|
2019-10-14 15:27:08 +00:00
|
|
|
ami = data.aws_ami.main.image_id
|
|
|
|
instance_type = var.instance_type
|
|
|
|
key_name = module.keys.key_name
|
|
|
|
vpc_security_group_ids = [aws_security_group.primary.id]
|
|
|
|
count = var.client_count
|
|
|
|
depends_on = [aws_instance.server]
|
2018-12-17 17:40:09 +00:00
|
|
|
|
|
|
|
# Instance tags
|
2019-10-14 15:27:08 +00:00
|
|
|
tags = {
|
2018-12-17 17:40:09 +00:00
|
|
|
Name = "${local.random_name}-client-${count.index}"
|
|
|
|
ConsulAutoJoin = "auto-join"
|
2019-10-14 15:27:08 +00:00
|
|
|
SHA = var.nomad_sha
|
|
|
|
User = data.aws_caller_identity.current.arn
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 15:27:08 +00:00
|
|
|
ebs_block_device {
|
2019-09-17 18:06:50 +00:00
|
|
|
device_name = "/dev/xvdd"
|
|
|
|
volume_type = "gp2"
|
|
|
|
volume_size = "50"
|
|
|
|
delete_on_termination = "true"
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 15:27:08 +00:00
|
|
|
iam_instance_profile = aws_iam_instance_profile.instance_profile.name
|
2018-12-17 17:40:09 +00:00
|
|
|
|
2019-10-25 12:08:24 +00:00
|
|
|
# copy up all provisioning scripts and configs
|
|
|
|
provisioner "file" {
|
|
|
|
source = "shared/"
|
|
|
|
destination = "/ops/shared"
|
|
|
|
|
|
|
|
connection {
|
|
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
|
|
type = "ssh"
|
|
|
|
user = "ubuntu"
|
|
|
|
private_key = module.keys.private_key_pem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 17:40:09 +00:00
|
|
|
provisioner "file" {
|
2019-10-14 15:27:08 +00:00
|
|
|
content = file(
|
|
|
|
"${path.root}/configs/${var.indexed == false ? "client.hcl" : "indexed/client-${count.index}.hcl"}",
|
|
|
|
)
|
2018-12-17 17:40:09 +00:00
|
|
|
destination = "/tmp/client.hcl"
|
|
|
|
|
|
|
|
connection {
|
2019-10-14 15:27:08 +00:00
|
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
|
|
type = "ssh"
|
2018-12-17 17:40:09 +00:00
|
|
|
user = "ubuntu"
|
2019-10-14 15:27:08 +00:00
|
|
|
private_key = module.keys.private_key_pem
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
2019-10-25 12:08:24 +00:00
|
|
|
"chmod +x /ops/shared/config/provision-client.sh",
|
|
|
|
"/ops/shared/config/provision-client.sh aws '${var.retry_join}' ${var.nomad_sha}",
|
2018-12-17 17:40:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
connection {
|
2019-10-14 15:27:08 +00:00
|
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
|
|
type = "ssh"
|
2018-12-17 17:40:09 +00:00
|
|
|
user = "ubuntu"
|
2019-10-14 15:27:08 +00:00
|
|
|
private_key = module.keys.private_key_pem
|
2018-12-17 17:40:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|