-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from silinternational/develop
Several recent updates
- Loading branch information
Showing
19 changed files
with
434 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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}" | ||
} | ||
``` |
This file contains 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
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}")}" | ||
} |
This file contains 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
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}" | ||
} |
This file contains 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
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 | ||
} |
This file contains 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
This file contains 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
This file contains 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
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}" | ||
} | ||
``` |
Oops, something went wrong.