Skip to content

Commit a220c5e

Browse files
Normal ECS
0 parents  commit a220c5e

28 files changed

+501
-0
lines changed

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TF_VAR_fastladder_db_pass=
2+
TF_VAR_fastladder_secret_key_base=
3+
AWS_DEFAULT_REGION=us-east-1

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.terraform.*
2+
.terraform/
3+
terraform.tfstate
4+
terraform.tfstate.*

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Tsuyoshi Hoshino
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

terraform/main.tf

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
terraform {
2+
backend "s3" {}
3+
}
4+
5+
provider "aws" {}
6+
7+
variable "aws_autoscaling_group_desired_capacity" {
8+
default = 1
9+
}
10+
11+
variable "aws_autoscaling_group_max_size" {
12+
default = 1
13+
}
14+
15+
variable "aws_autoscaling_group_min_size" {
16+
default = 1
17+
}
18+
19+
variable "aws_db_instance_fastladder_instance_class" {
20+
default = "db.t2.micro"
21+
}
22+
23+
variable "aws_ecs_service_desired_count_rails" {
24+
default = 1
25+
}
26+
27+
variable "aws_launch_configuration_fastladder_image_id" {
28+
default = "ami-fad25980"
29+
}
30+
31+
variable "aws_launch_configuration_fastladder_instance_type" {
32+
default = "t2.micro"
33+
}
34+
35+
variable "resource_base_name" {
36+
default = "fastladder"
37+
}
38+
39+
variable "fastladder_db_name" {
40+
default = "fastladder"
41+
}
42+
43+
variable "fastladder_db_pass" {}
44+
45+
variable "fastladder_db_user" {
46+
default = "root"
47+
}
48+
49+
variable "fastladder_secret_key_base" {}
50+
51+
module "fastladder" {
52+
aws_autoscaling_group_desired_capacity = "${var.aws_autoscaling_group_desired_capacity}"
53+
aws_autoscaling_group_max_size = "${var.aws_autoscaling_group_max_size}"
54+
aws_autoscaling_group_min_size = "${var.aws_autoscaling_group_min_size}"
55+
aws_db_instance_fastladder_instance_class = "${var.aws_db_instance_fastladder_instance_class}"
56+
aws_ecs_service_desired_count_rails = "${var.aws_ecs_service_desired_count_rails}"
57+
aws_launch_configuration_fastladder_image_id = "${var.aws_launch_configuration_fastladder_image_id}"
58+
aws_launch_configuration_fastladder_instance_type = "${var.aws_launch_configuration_fastladder_instance_type}"
59+
resource_base_name = "${var.resource_base_name}"
60+
fastladder_db_name = "${var.fastladder_db_name}"
61+
fastladder_db_pass = "${var.fastladder_db_pass}"
62+
fastladder_db_user = "${var.fastladder_db_user}"
63+
fastladder_secret_key_base = "${var.fastladder_secret_key_base}"
64+
source = "./modules/fastladder"
65+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "aws_alb" "fastladder" {
2+
name = "${var.resource_base_name}"
3+
4+
subnets = [
5+
"${aws_subnet.fastladder_public_a.id}",
6+
"${aws_subnet.fastladder_public_c.id}",
7+
]
8+
9+
security_groups = [
10+
"${aws_security_group.fastladder_alb.id}",
11+
]
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "aws_alb_listener" "fastladder_rails" {
2+
load_balancer_arn = "${aws_alb.fastladder.arn}"
3+
port = "80"
4+
protocol = "HTTP"
5+
6+
default_action {
7+
target_group_arn = "${aws_alb_target_group.fastladder_rails.id}"
8+
type = "forward"
9+
}
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_alb_target_group" "fastladder_rails" {
2+
deregistration_delay = 10
3+
4+
health_check {
5+
healthy_threshold = 2
6+
interval = 60
7+
matcher = "302"
8+
path = "/"
9+
timeout = 10
10+
unhealthy_threshold = 5
11+
}
12+
13+
name = "${var.resource_base_name}-rails"
14+
port = 80
15+
protocol = "HTTP"
16+
17+
stickiness {
18+
type = "lb_cookie"
19+
}
20+
21+
vpc_id = "${aws_vpc.fastladder.id}"
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "aws_autoscaling_group" "fastladder" {
2+
desired_capacity = "${var.aws_autoscaling_group_desired_capacity}"
3+
health_check_type = "EC2"
4+
launch_configuration = "${aws_launch_configuration.fastladder.name}"
5+
max_size = "${var.aws_autoscaling_group_max_size}"
6+
min_size = "${var.aws_autoscaling_group_min_size}"
7+
name = "${var.resource_base_name}"
8+
9+
vpc_zone_identifier = [
10+
"${aws_subnet.fastladder_public_a.id}",
11+
"${aws_subnet.fastladder_public_c.id}",
12+
]
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "aws_cloudwatch_log_group" "fastladder" {
2+
name = "${var.resource_base_name}"
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "aws_db_instance" "fastladder" {
2+
allocated_storage = 20
3+
auto_minor_version_upgrade = true
4+
backup_retention_period = 7
5+
backup_window = "20:00-21:00"
6+
db_subnet_group_name = "${aws_db_subnet_group.fastladder.name}"
7+
engine = "postgres"
8+
engine_version = "9.6.1"
9+
identifier = "${var.resource_base_name}"
10+
instance_class = "${var.aws_db_instance_fastladder_instance_class}"
11+
multi_az = false
12+
name = "fastladder"
13+
parameter_group_name = "${aws_db_parameter_group.fastladder.name}"
14+
password = "${var.fastladder_db_pass}"
15+
skip_final_snapshot = true
16+
username = "${var.fastladder_db_user}"
17+
18+
vpc_security_group_ids = [
19+
"${aws_security_group.fastladder_db.id}",
20+
]
21+
}

0 commit comments

Comments
 (0)