· 7 years ago · Jun 22, 2018, 11:08 PM
1provider "aws" {
2 access_key = "xxxxx"
3 secret_key = "xxxxxx"
4 region = "us-east-1"
5}
6
7resource "aws_security_group" "allow_all" {
8 name = "allow_all"
9 description = "Allow all inbound traffic"
10 vpc_id = "${aws_vpc.jmeter_vpc.id}"
11 ingress {
12 from_port = 0
13 to_port = 65535
14 protocol = "tcp"
15 cidr_blocks = ["0.0.0.0/0"]
16 }
17 egress {
18 from_port = 0
19 to_port = 0
20 protocol = "-1"
21 cidr_blocks = ["0.0.0.0/0"]
22 }
23 tags {
24 Name = "allow_all"
25 }
26}
27resource "aws_internet_gateway" "main" {
28 vpc_id = "${aws_vpc.jmeter_vpc.id}"
29
30 tags {
31 Name = "main"
32 }
33}
34
35resource "aws_default_route_table" "r" {
36 default_route_table_id = "${aws_vpc.jmeter_vpc.default_route_table_id}"
37
38 route {
39 cidr_block = "0.0.0.0/0"
40 gateway_id = "${aws_internet_gateway.main.id}"
41 }
42
43 tags {
44 Name = "default table"
45 }
46}
47
48resource "aws_vpc" "jmeter_vpc" {
49 cidr_block = "172.16.0.0/16"
50
51 tags {
52 Name = "tf-jmeter"
53 }
54}
55
56resource "aws_subnet" "jmeter_subnet" {
57 vpc_id = "${aws_vpc.jmeter_vpc.id}"
58 cidr_block = "172.16.10.0/24"
59 availability_zone = "us-east-1a"
60
61 tags {
62 Name = "tf-jmeter"
63 }
64}
65
66resource "aws_instance" "worker0" {
67 count = 25
68 ami = "ami-2757f631"
69 instance_type = "c4.2xlarge"
70 key_name = "mdstrm"
71 security_groups = ["${aws_security_group.allow_all.id}"]
72
73 connection {
74 user = "ubuntu"
75 private_key = "${file("~/.ssh/mdstrm.pem")}"
76 }
77
78 associate_public_ip_address = true
79 subnet_id = "${aws_subnet.jmeter_subnet.id}"
80
81 tags {
82 Name = "terraform-test"
83 }
84
85 provisioner "remote-exec" {
86 inline = [
87 "sudo apt update -y",
88 "sudo apt install apache2-utils -y",
89 "sudo ab -n 20000 -c 100 -H 'User-Agent: xxxxx' 'http://us--dr-mia--p--e--6.cxxxxx/live-stream/57bf686a61ff39e1085d43e1/10m.ts?ot=xxxxxxx&ote=xxxxxx'"
90 ]
91 }
92}