Last active
November 29, 2018 05:01
-
-
Save wreulicke/67409840441c5edbc4fe42c5345950e9 to your computer and use it in GitHub Desktop.
負荷試験用にECS立ち上げるやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2008-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "ec2.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2008-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "ecs.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "ap-northeast-1" | |
profile = "personal" | |
} | |
resource "aws_vpc" "load_test_vpc" { | |
cidr_block = "10.2.0.0/16" | |
enable_dns_support = true | |
enable_dns_hostnames = true | |
tags { | |
Name = "load-test" | |
} | |
} | |
resource "aws_internet_gateway" "load_test" { | |
vpc_id = "${aws_vpc.load_test_vpc.id}" | |
tags { | |
Name = "load_test" | |
} | |
} | |
data "aws_availability_zones" "available" {} | |
resource "aws_subnet" "load_test_1" { | |
vpc_id = "${aws_vpc.load_test_vpc.id}" | |
cidr_block = "${cidrsubnet(aws_vpc.load_test_vpc.cidr_block, 8, 0)}" | |
availability_zone = "${data.aws_availability_zones.available.names[0]}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "load-test" | |
} | |
} | |
resource "aws_subnet" "load_test_2" { | |
vpc_id = "${aws_vpc.load_test_vpc.id}" | |
cidr_block = "${cidrsubnet(aws_vpc.load_test_vpc.cidr_block, 8, 1)}" | |
availability_zone = "${data.aws_availability_zones.available.names[1]}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "load-test" | |
} | |
} | |
resource "aws_subnet" "load_test_3" { | |
vpc_id = "${aws_vpc.load_test_vpc.id}" | |
cidr_block = "${cidrsubnet(aws_vpc.load_test_vpc.cidr_block, 8, 2)}" | |
availability_zone = "${data.aws_availability_zones.available.names[2]}" | |
map_public_ip_on_launch = true | |
tags { | |
Name = "load-test" | |
} | |
} | |
resource "aws_route_table" "route_table" { | |
vpc_id = "${aws_vpc.load_test_vpc.id}" | |
route { | |
cidr_block = "0.0.0.0/0" | |
gateway_id = "${aws_internet_gateway.load_test.id}" | |
} | |
tags { | |
Name = "load_test" | |
} | |
} | |
resource "aws_route_table_association" "public_association1" { | |
subnet_id = "${aws_subnet.load_test_1.id}" | |
route_table_id = "${aws_route_table.route_table.id}" | |
} | |
resource "aws_route_table_association" "public_association2" { | |
subnet_id = "${aws_subnet.load_test_2.id}" | |
route_table_id = "${aws_route_table.route_table.id}" | |
} | |
resource "aws_route_table_association" "public_association3" { | |
subnet_id = "${aws_subnet.load_test_3.id}" | |
route_table_id = "${aws_route_table.route_table.id}" | |
} | |
resource "aws_ecs_cluster" "load-test" { | |
name = "load-test" | |
} | |
resource "aws_iam_role" "ecs_instance_role" { | |
name = "EcsInstanceRole" | |
assume_role_policy = "${file("ec2-assume-role.json")}" | |
} | |
resource "aws_iam_role" "ecs_service_role" { | |
name = "EcsServiceRole" | |
assume_role_policy = "${file("ecs-assume-role.json")}" | |
} | |
resource "aws_iam_policy_attachment" "ecs_instance_role_attach" { | |
name = "ecs-instance-role-attach" | |
roles = ["${aws_iam_role.ecs_instance_role.name}"] | |
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role" | |
} | |
resource "aws_iam_policy_attachment" "ecs_service_role_attach" { | |
name = "ecs-service-role-attach" | |
roles = ["${aws_iam_role.ecs_service_role.name}"] | |
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole" | |
} | |
resource "aws_iam_instance_profile" "ecs" { | |
name = "ecs-instance-profile" | |
path = "/" | |
role = "${aws_iam_role.ecs_instance_role.name}" | |
} | |
resource "aws_placement_group" "load_test" { | |
name = "load-test" | |
strategy = "cluster" | |
} | |
resource "aws_security_group" "load-test" { | |
name_prefix = "load-test" | |
description = "Used in the terraform" | |
vpc_id = "${aws_vpc.load_test_vpc.id}" | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
resource "aws_launch_configuration" "load_test" { | |
name_prefix = "load-test-config" | |
image_id = "ami-05b296a384694dfa4" | |
instance_type = "t3.medium" | |
iam_instance_profile = "${aws_iam_instance_profile.ecs.name}" | |
user_data = "${file("user_data.bash")}" | |
key_name = "ecs-test" | |
security_groups = ["${aws_security_group.load-test.id}"] | |
ebs_optimized = true | |
associate_public_ip_address = true | |
lifecycle { | |
create_before_destroy = true | |
} | |
} | |
resource "aws_autoscaling_group" "load-test-group" { | |
name = "load-test-group" | |
count = 1 | |
min_size = 0 | |
max_size = 1 | |
placement_group = "${aws_placement_group.load_test.id}" | |
launch_configuration = "${aws_launch_configuration.load_test.name}" | |
vpc_zone_identifier = [ | |
"${aws_subnet.load_test_1.id}", | |
"${aws_subnet.load_test_2.id}", | |
"${aws_subnet.load_test_3.id}", | |
] | |
tag { | |
key = "Name" | |
value = "load-test" | |
propagate_at_launch = true | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cat << EOF >> /etc/ecs/ecs.config | |
ECS_CLUSTER=load-test | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment