Skip to content

Commit

Permalink
Merge pull request #12 from silinternational/develop
Browse files Browse the repository at this point in the history
Several recent updates
  • Loading branch information
fillup authored Apr 6, 2018
2 parents 648bf3c + dddb39a commit 65cb3f0
Show file tree
Hide file tree
Showing 19 changed files with 434 additions and 37 deletions.
1 change: 1 addition & 0 deletions aws/alb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ groups for traffic and a default target group.
- `healthy_threshold` - Default: `5`
- `unhealthy_threshold` - Default: `2`
- `health_check_status_codes` - Default: `200`, separate multiple values with comma, ex: `200,204`
- `load_balancer_type` - Options: `application` or `network`. Default: `application`

## Outputs

Expand Down
9 changes: 5 additions & 4 deletions aws/alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Create application load balancer
*/
resource "aws_alb" "alb" {
name = "${coalesce(var.alb_name, "alb-${var.app_name}-${var.app_env}")}"
internal = "${var.internal}"
security_groups = ["${var.security_groups}"]
subnets = ["${var.subnets}"]
name = "${coalesce(var.alb_name, "alb-${var.app_name}-${var.app_env}")}"
internal = "${var.internal}"
security_groups = ["${var.security_groups}"]
subnets = ["${var.subnets}"]
load_balancer_type = "${var.load_balancer_type}"

tags {
Name = "${coalesce(var.alb_name, "alb-${var.app_name}-${var.app_env}")}"
Expand Down
6 changes: 5 additions & 1 deletion aws/alb/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ variable "internal" {

variable "ssl_policy" {
type = "string"
default = "ELBSecurityPolicy-2015-05"
default = "ELBSecurityPolicy-2016-08"
}

variable "tg_name" {
Expand Down Expand Up @@ -101,3 +101,7 @@ variable "unhealthy_threshold" {
variable "health_check_status_codes" {
default = "200"
}

variable "load_balancer_type" {
default = "application"
}
4 changes: 4 additions & 0 deletions aws/asg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ an auto scaling group that uses the configuration.
- `ecs_instance_profile_id` - IAM profile ID for ecsInstanceProfile
- `ecs_cluster_name` - ECS cluster name for registering instances

## Optional Inputs

- `key_name` - Name of the AWS key pair to allow ssh access, default is ""

## Outputs

- `ecs_cluster_name` - The ECS cluster name
Expand Down
1 change: 1 addition & 0 deletions aws/asg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ resource "aws_launch_configuration" "as_conf" {
instance_type = "${var.aws_instance["instance_type"]}"
security_groups = ["${var.default_sg_id}"]
iam_instance_profile = "${var.ecs_instance_profile_id}"
key_name = "${var.key_name}"

root_block_device {
volume_size = "${var.aws_instance["volume_size"]}"
Expand Down
5 changes: 5 additions & 0 deletions aws/asg/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ variable "ecs_instance_profile_id" {
variable "ecs_cluster_name" {
type = "string"
}

variable "key_name" {
type = "string"
default = ""
}
50 changes: 50 additions & 0 deletions aws/ecs/service-no-alb-with-volume/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# aws/ecs/service-no-alb-with-volume - EC2 Container Service Service/Task without load balancer with volume
This module is used to create an ECS service as well as task definition

## What this does

- Create task definition
- Create service

## Required Inputs

- `cluster_id` - ID for ECS Cluster
- `service_name` - Name of service, all lowercase, no spaces.
- `service_env` - Name of environment, used in naming task definition. Ex: `staging`
- `container_def_json` - JSON for container definition.
- `desired_count` - Number of tasks to run in service
- `volume_name` - Name for volume
- `volume_host_path` - Path on host EC2 instance to mount volume

### Optional Inputs

- `task_role_arn` - ARN for role to assign to task definition. Default: `blank`
- `network_mode` - Networking mode for task. Default: `bridge`
- `deployment_maximum_percent` - Upper limit of tasks that can run during a deployment. Default: `200`%
- `deployment_minimum_healthy_percent` - Lower limit of tasks that must be running during a deployment. Default: `50`%

## Outputs

- `task_def_arn` - ARN for task definition.
- `task_def_family` - Family name of task definition.
- `task_def_revision` - Revision number of task definition.
- `task_def_revision_via_data` - Revision number of task def via data resource
- `service_id` - ID/ARN for service
- `service_name` - Name of service
- `service_cluster` - Name of ECS cluster service was placed in
- `service_desired_count` - Desired task count for service

## Usage Example

```hcl
module "ecsservice" {
source = "github.com/silinternational/terraform-modules//aws/ecs/service-no-alb-with-volume"
cluster_id = "${module.ecscluster.ecs_cluster_id}"
service_name = "${var.app_name}"
service_env = "${var.app_env}"
container_def_json = "${file("task-definition.json")}"
desired_count = 2
volume_name = "${var.volume_name}"
volume_host_path = "${var.volume_host_path}"
}
```
41 changes: 41 additions & 0 deletions aws/ecs/service-no-alb-with-volume/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Get task definition data
*/
data "aws_ecs_task_definition" "td" {
task_definition = "${aws_ecs_task_definition.td.family}"
depends_on = ["aws_ecs_task_definition.td"]
}

/*
* Create task definition
*/
resource "aws_ecs_task_definition" "td" {
family = "${var.service_name}-${var.service_env}"
container_definitions = "${var.container_def_json}"
task_role_arn = "${var.task_role_arn}"
network_mode = "${var.network_mode}"

volume {
name = "${var.volume_name}"
host_path = "${var.volume_host_path}"
}
}

/*
* Create ECS Service
*/
resource "aws_ecs_service" "service" {
name = "${var.service_name}"
cluster = "${var.cluster_id}"
desired_count = "${var.desired_count}"
deployment_maximum_percent = "${var.deployment_maximum_percent}"
deployment_minimum_healthy_percent = "${var.deployment_minimum_healthy_percent}"

placement_strategy {
type = "spread"
field = "instanceId"
}

# Track the latest ACTIVE revision
task_definition = "${aws_ecs_task_definition.td.family}:${max("${aws_ecs_task_definition.td.revision}", "${data.aws_ecs_task_definition.td.revision}")}"
}
37 changes: 37 additions & 0 deletions aws/ecs/service-no-alb-with-volume/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Task definition outputs
*/
output "task_def_arn" {
value = "${aws_ecs_task_definition.td.arn}"
}

output "task_def_family" {
value = "${aws_ecs_task_definition.td.family}"
}

output "task_def_revision" {
value = "${aws_ecs_task_definition.td.revision}"
}

output "task_def_revision_via_data" {
value = "${data.aws_ecs_task_definition.td.revision}"
}

/*
* Service outputs
*/
output "service_id" {
value = "${aws_ecs_service.service.id}"
}

output "service_name" {
value = "${aws_ecs_service.service.name}"
}

output "service_cluster" {
value = "${aws_ecs_service.service.cluster}"
}

output "service_desired_count" {
value = "${aws_ecs_service.service.desired_count}"
}
53 changes: 53 additions & 0 deletions aws/ecs/service-no-alb-with-volume/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Required Variables
*/
variable "cluster_id" {
type = "string"
}

variable "service_name" {
type = "string"
}

variable "service_env" {
type = "string"
}

variable "container_def_json" {
type = "string"
}

variable "desired_count" {
type = "string"
}

variable "volume_name" {
type = "string"
}

variable "volume_host_path" {
type = "string"
}

/*
* Optional Variables
*/
variable "task_role_arn" {
type = "string"
default = ""
}

variable "network_mode" {
type = "string"
default = "bridge"
}

variable "deployment_maximum_percent" {
type = "string"
default = 200
}

variable "deployment_minimum_healthy_percent" {
type = "string"
default = 50
}
12 changes: 6 additions & 6 deletions aws/ecs/service-no-alb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ This module is used to create an ECS service as well as task definition
- `task_def_arn` - ARN for task definition.
- `task_def_family` - Family name of task definition.
- `task_def_revision` - Revision number of task definition.
- `task_def_revision_via_data` - Revision number of task def via data resource
- `service_id` - ID/ARN for service
- `service_name` - Name of service
- `service_cluster` - Name of ECS cluster service was placed in
- `service_role` - IAM role for service
- `service_desired_count` - Desired task count for service

## Usage Example

```hcl
module "ecsservice" {
source = "github.com/silinternational/terraform-modules//aws/ecs/service-no-alb"
cluster_id = "${module.ecscluster.ecs_cluster_id}"
service_name = "${var.app_name}"
service_env = "${var.app_env}"
source = "github.com/silinternational/terraform-modules//aws/ecs/service-no-alb"
cluster_id = "${module.ecscluster.ecs_cluster_id}"
service_name = "${var.app_name}"
service_env = "${var.app_env}"
container_def_json = "${file("task-definition.json")}"
desired_count = 2
desired_count = 2
}
```
25 changes: 0 additions & 25 deletions aws/ecs/service-no-alb/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,6 @@ variable "desired_count" {
/*
* Optional Variables
*/
variable "port" {
type = "string"
default = 80
}

variable "protocol" {
type = "string"
default = "HTTP"
}

variable "access_logs_enabled" {
type = "string"
default = "false"
}

variable "access_logs_bucket" {
type = "string"
default = ""
}

variable "ssl_policy" {
type = "string"
default = "ELBSecurityPolicy-2015-05"
}

variable "task_role_arn" {
type = "string"
default = ""
Expand Down
60 changes: 60 additions & 0 deletions aws/ecs/service-only-with-volume/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# aws/ecs/service-only - EC2 Container Service Service/Task
This module is used to create an ECS service as well as task definition

## What this does

- Create IAM role: `ecsServiceRole`
- Create task definition
- Create service

## Required Inputs

- `cluster_id` - ID for ECS Cluster
- `service_name` - Name of service, all lowercase, no spaces.
- `service_env` - Name of environment, used in naming task definition. Ex: `staging`
- `container_def_json` - JSON for container definition.
- `desired_count` - Number of tasks to run in service
- `tg_arn` - Target Group ARN for ALB to register with
- `lb_container_name` - Container name from `container_def_json` that should be used with target group / alb
- `lb_container_port` - Container port that should be used with target group / alb
- `ecsServiceRole_arn` - ARN to IAM ecsServiceRole
- `volume_name` - Name for volume
- `volume_host_path` - Path on host EC2 instance to mount volume

### Optional Inputs

- `task_role_arn` - ARN for role to assign to task definition. Default: `blank`
- `network_mode` - Networking mode for task. Default: `bridge`
- `deployment_maximum_percent` - Upper limit of tasks that can run during a deployment. Default: `200`%
- `deployment_minimum_healthy_percent` - Lower limit of tasks that must be running during a deployment. Default: `50`%

## Outputs

- `task_def_arn` - ARN for task definition.
- `task_def_family` - Family name of task definition.
- `task_def_revision` - Revision number of task definition.
- `task_def_revision_via_data` - Task def revision from data resource
- `service_id` - ID/ARN for service
- `service_name` - Name of service
- `service_cluster` - Name of ECS cluster service was placed in
- `service_role` - IAM role for service
- `service_desired_count` - Desired task count for service

## Usage Example

```hcl
module "ecsservice" {
source = "github.com/silinternational/terraform-modules//aws/ecs/service-only"
cluster_id = "${module.ecscluster.ecs_cluster_id}"
service_name = "${var.app_name}"
service_env = "${var.app_env}"
container_def_json = "${file("task-definition.json")}"
desired_count = 2
tg_arn = "${data.terraform_remote_state.cluster.alb_default_tg_arn}"
lb_container_name = "app"
lb_container_port = 80
ecsServiceRole_arn = "${data.terraform_remote_state.core.ecsServiceRole_arn}"
volume_name = "${var.volume_name}"
volume_host_path = "${var.volume_host_path}"
}
```
Loading

0 comments on commit 65cb3f0

Please sign in to comment.