Skip to content

Commit

Permalink
Restructuring cloud infra (everything works now)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas committed Nov 25, 2017
1 parent 59afa15 commit 317f48c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 58 deletions.
4 changes: 2 additions & 2 deletions aws/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# AWS

Ensure you have Terraform `0.11.0` installed:
Ensure that you have Terraform `0.11.0` installed:

```
brew install terraform
brew install terraform
brew upgrade terraform
```

Setup environment:
Expand Down
47 changes: 12 additions & 35 deletions aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ resource "aws_ecs_cluster" "main" {
name = "${var.ecs_cluster_name}"
}

resource "aws_autoscaling_group" "ecs-cluster" {
availability_zones = ["${var.availability_zone}"]
name = "ECS ${var.ecs_cluster_name}"
min_size = "${var.autoscale_min}"
max_size = "${var.autoscale_max}"
desired_capacity = "${var.autoscale_desired}"
health_check_type = "EC2"
launch_configuration = "${aws_launch_configuration.ecs.name}"
vpc_zone_identifier = ["${aws_subnet.main.id}"]
}

resource "aws_launch_configuration" "ecs" {
name = "ECS ${var.ecs_cluster_name}"
iam_instance_profile = "${aws_iam_instance_profile.ecs.name}"
Expand All @@ -35,30 +24,18 @@ resource "aws_launch_configuration" "ecs" {
associate_public_ip_address = true
}

resource "aws_iam_role" "ecs_host_role" {
name = "ecs_host_role"
assume_role_policy = "${file("policies/ecs-role.json")}"
}

resource "aws_iam_role_policy" "ecs_instance_role_policy" {
name = "ecs_instance_role_policy"
policy = "${file("policies/ecs-instance-role-policy.json")}"
role = "${aws_iam_role.ecs_host_role.id}"
}

resource "aws_iam_role" "ecs_service_role" {
name = "ecs_service_role"
assume_role_policy = "${file("policies/ecs-role.json")}"
}

resource "aws_iam_role_policy" "ecs_service_role_policy" {
name = "ecs_service_role_policy"
policy = "${file("policies/ecs-service-role-policy.json")}"
role = "${aws_iam_role.ecs_service_role.id}"
resource "aws_autoscaling_group" "ecs" {
name = "ECS ${var.ecs_cluster_name}"
availability_zones = ["${var.availability_zone}"]
min_size = 1
max_size = 1
desired_capacity = 1
health_check_type = "EC2"
launch_configuration = "${aws_launch_configuration.ecs.name}"
vpc_zone_identifier = ["${aws_subnet.main.id}"]
}

resource "aws_iam_instance_profile" "ecs" {
name = "ecs-instance-profile"
path = "/"
role = "${aws_iam_role.ecs_host_role.name}"
resource "aws_ecs_task_definition" "glados-server" {
family = "glados-server"
container_definitions = "${file("task-definitions/glados-server.json")}"
}
28 changes: 28 additions & 0 deletions aws/profiles.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

resource "aws_iam_role" "ecs_host_role" {
name = "ecs_host_role"
assume_role_policy = "${file("policies/ecs-role.json")}"
}

resource "aws_iam_role_policy" "ecs_instance_role_policy" {
name = "ecs_instance_role_policy"
policy = "${file("policies/ecs-instance-role-policy.json")}"
role = "${aws_iam_role.ecs_host_role.id}"
}

resource "aws_iam_role" "ecs_service_role" {
name = "ecs_service_role"
assume_role_policy = "${file("policies/ecs-role.json")}"
}

resource "aws_iam_role_policy" "ecs_service_role_policy" {
name = "ecs_service_role_policy"
policy = "${file("policies/ecs-service-role-policy.json")}"
role = "${aws_iam_role.ecs_service_role.id}"
}

resource "aws_iam_instance_profile" "ecs" {
name = "ecs-instance-profile"
path = "/"
role = "${aws_iam_role.ecs_host_role.name}"
}
47 changes: 28 additions & 19 deletions aws/services.tf
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
resource "aws_elb" "test-http" {
name = "test-http-elb"
resource "aws_elb" "glados-elb" {
name = "glados-elb"
security_groups = ["${aws_security_group.load_balancers.id}"]
subnets = ["${aws_subnet.main.id}"]

connection_draining = true
cross_zone_load_balancing = true

# WebSocket route
listener {
lb_protocol = "http"
lb_protocol = "tcp"
lb_port = 80
instance_protocol = "http"
instance_protocol = "tcp"
instance_port = 3000
}


# Static route
listener {
lb_protocol = "http"
lb_port = 8000
instance_protocol = "http"
instance_port = 8000
}

# Healthcheck definition
health_check {
healthy_threshold = 3
unhealthy_threshold = 2
healthy_threshold = 2
unhealthy_threshold = 10
target = "TCP:3000"
interval = 15
timeout = 10
interval = 10
timeout = 5
}
}

resource "aws_ecs_task_definition" "test-http" {
family = "test-http"
container_definitions = "${file("task-definitions/test-http.json")}"
}

resource "aws_ecs_service" "test-http" {
name = "test-http"
resource "aws_ecs_service" "glados-server" {
name = "glados-server"
cluster = "${aws_ecs_cluster.main.id}"
task_definition = "${aws_ecs_task_definition.test-http.family}:${aws_ecs_task_definition.test-http.revision}"
task_definition = "${aws_ecs_task_definition.glados-server.family}:${aws_ecs_task_definition.glados-server.revision}"
iam_role = "${aws_iam_role.ecs_service_role.arn}"
desired_count = 1
depends_on = ["aws_iam_role_policy.ecs_service_role_policy"]

load_balancer {
elb_name = "${aws_elb.test-http.id}"
container_name = "test-http"
elb_name = "${aws_elb.glados-elb.id}"
container_name = "glados-server"
container_port = 3000
}
}

# resource "aws_s3_bucket" "glados-bucket" {
# bucket = "glados-bucket"
# }
9 changes: 7 additions & 2 deletions aws/task-definitions/glados-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
"image": "nardeas/glados:server",
"cpu": 512,
"memory": 512,
"links": [],
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000,
"protocol": "tcp"
},
{
"containerPort": 8000,
"hostPort": 8000,
"protocol": "tcp"
}
],
"essential": true,
"entryPoint": [],
"links": [],
"command": [],
"entryPoint": [],
"environment": [],
"mountPoints": [],
"volumesFrom": []
Expand Down

0 comments on commit 317f48c

Please sign in to comment.