2020-12-11 19:11:14 +00:00
|
|
|
data "aws_ami" "test" {
|
|
|
|
most_recent = true
|
|
|
|
|
|
|
|
owners = var.ami_owners
|
|
|
|
|
|
|
|
filter {
|
|
|
|
name = "virtualization-type"
|
|
|
|
values = ["hvm"]
|
|
|
|
}
|
|
|
|
|
|
|
|
filter {
|
|
|
|
name = "is-public"
|
|
|
|
values = ["false"]
|
|
|
|
}
|
|
|
|
|
|
|
|
filter {
|
|
|
|
name = "name"
|
|
|
|
values = ["consul-test-*"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 01:16:09 +00:00
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Start up test servers to run tests from
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
resource "aws_security_group" "test-servers" {
|
|
|
|
name = "${local.random_name}-test-server-sg"
|
|
|
|
vpc_id = module.vpc.vpc_id
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 8500
|
|
|
|
to_port = 8500
|
2020-12-11 19:11:14 +00:00
|
|
|
security_groups = [module.consul_clients.security_group_id]
|
2020-10-06 01:16:09 +00:00
|
|
|
protocol = "6"
|
2022-05-16 20:37:45 +00:00
|
|
|
cidr_blocks = ["10.0.0.0/16"]
|
2020-10-06 01:16:09 +00:00
|
|
|
}
|
|
|
|
ingress {
|
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
|
|
|
protocol = "6"
|
2022-05-16 20:37:45 +00:00
|
|
|
cidr_blocks = ["10.0.0.0/16"]
|
2020-10-06 01:16:09 +00:00
|
|
|
}
|
|
|
|
egress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
2022-05-16 20:37:45 +00:00
|
|
|
cidr_blocks = ["10.0.0.0/16"]
|
2020-10-06 01:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 19:11:14 +00:00
|
|
|
resource "aws_instance" "test-server" {
|
|
|
|
ami = var.test_server_ami == null ? data.aws_ami.test.id : var.test_server_ami
|
|
|
|
instance_type = var.test_instance_type
|
|
|
|
key_name = module.keys.key_name
|
|
|
|
vpc_security_group_ids = toset([aws_security_group.test-servers.id])
|
2020-10-06 01:16:09 +00:00
|
|
|
associate_public_ip_address = var.test_public_ip
|
2020-12-11 19:11:14 +00:00
|
|
|
subnet_id = (module.vpc.public_subnets)[0]
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"export LB_ENDPOINT=${module.alb.this_lb_dns_name}",
|
2020-12-15 23:03:44 +00:00
|
|
|
"k6 run -q /home/ubuntu/scripts/loadtest.js"
|
2020-12-11 19:11:14 +00:00
|
|
|
]
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
|
|
|
user = "ubuntu"
|
|
|
|
timeout = "1m"
|
|
|
|
private_key = module.keys.private_key_pem
|
|
|
|
host = aws_instance.test-server.public_ip
|
2020-10-06 01:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|