|
1 | 1 | # Terraform AWS ECS Stack #
|
2 | 2 | [](https://circleci.com/gh/unifio/terraform-aws-ecs/tree/master)
|
3 | 3 |
|
4 |
| -Terraform module for the deployment of an AWS ECS cluster. |
| 4 | +Terraform module for the deployment of an AWS Elastic Container Service (ECS) cluster. |
5 | 5 |
|
6 | 6 | ## Requirements ##
|
7 | 7 |
|
8 |
| -- Terraform 0.6.16 or newer |
| 8 | +- Terraform 0.8.0 or newer |
9 | 9 | - AWS provider
|
10 | 10 |
|
11 |
| -## Common Module ## |
12 |
| - |
13 |
| -The common module provisions the following resources for use with the ECS cluster: |
14 |
| - |
15 |
| -- IAM role & instance profile |
16 |
| -- Default policies |
17 |
| -- S3 bucket for ECS logs |
| 11 | +## Cluster module ## |
18 | 12 |
|
19 |
| -These resources can be shared amongst multiple clusters if desired. |
| 13 | +The cluster module provisions an ECS cluster and auto scaling group of agent instances. |
20 | 14 |
|
21 | 15 | ### Input Variables ###
|
22 | 16 |
|
23 |
| -Name | Type | Default | Description |
| 17 | +#### Resource tags |
| 18 | +Name | Type | Required | Description |
24 | 19 | --- | --- | --- | ---
|
25 |
| -`bucket_prefix` | string | | Label to prepend S3 bucket names with. |
26 |
| -`stack_item_fullname` | string | | Long form descriptive name for this stack item. This value is used to create the 'application' resource tag for resources created by this stack item. |
27 |
| -`stack_item_label` | string | | Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use. |
28 |
| - |
29 |
| -### Usage ### |
30 |
| - |
31 |
| -```js |
32 |
| -module "ecs" { |
33 |
| - source = "github.com/unifio/terraform-aws-ecs?ref=master//common" |
34 |
| - |
35 |
| - bucket_prefix = "xmplco" |
36 |
| - stack_item_fullname = "Example Cluster" |
37 |
| - stack_item_label = "xmpl" |
38 |
| -} |
39 |
| -``` |
| 20 | +`cluster_name` | string | yes | Name of the ECS based application stack. |
| 21 | +`stack_item_fullname` | string | yes | Long form descriptive name for this stack item. This value is used to create the 'application' resource tag for resources created by this stack item. |
| 22 | +`stack_item_label` | string | yes | Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use. |
40 | 23 |
|
41 |
| -### Outputs ### |
42 |
| - |
43 |
| -Name | Type | Description |
| 24 | +#### VPC parameters |
| 25 | +Name | Type | Required | Description |
44 | 26 | --- | --- | --- | ---
|
45 |
| -`ecs_agent_role_arn` | string | ARN of the ECS IAM role. |
46 |
| -`ecs_agent_role_id` | string | ID of the ECS IAM role. |
47 |
| -`ecs_agent_role_name` | string | Name of the ECS IAM role. |
48 |
| -`ecs_agent_role_unique_id` | string | Unique ID of the ECS IAM role. |
49 |
| -`ecs_logs_bucket_name` | string | Name of the ECS S3 logs bucket. |
50 |
| - |
51 |
| -## Cluster module ## |
52 |
| - |
53 |
| -The cluster module provisions an ECS cluster and auto scaling group of agent instances. |
| 27 | +`subnets` | list | yes | A list of subnet IDs to launch resources in. |
| 28 | +`vpc_id` | string | yes | ID of the target VPC. |
54 | 29 |
|
55 |
| -### Input Variables ### |
56 |
| - |
57 |
| -Name | Type | Default | Description |
| 30 | +#### Cluster launch configuration parameters |
| 31 | +Name | Type | Required | Description |
| 32 | +--- | --- | --- | --- |
| 33 | +`ami_override` | string | | Custom Amazon Machine Image (AMI) to associate with the launch configuration. |
| 34 | +`associate_public_ip_address` | string | | Flag for associating public IP addresses with instances managed by the auto scaling group. |
| 35 | +`ebs_optimized` | string | | Flag to enable EBS optimization. |
| 36 | +`ebs_vol_del_on_term` | string | Default: true | Whether the volume should be destroyed on instance termination. |
| 37 | +`ebs_vol_device_name` | string | | The name of the device to mount. |
| 38 | +`ebs_vol_encrypted` | string | | Whether the volume should be encrypted or not. Do not use this option if you are using `ebs_vol_snapshot_id` as the encrypted flag will be determined by the snapshot. |
| 39 | +`ebs_vol_iops` | string | Default: 2000 | The amount of provisioned IOPS. Only utilized with `ebs_vol_type` of `io1`. |
| 40 | +`ebs_vol_size` | string | | The size of the volume in gigabytes. |
| 41 | +`ebs_vol_snapshot_id` | string | | The Snapshot ID to mount. |
| 42 | +`ebs_vol_type` | string | Default: gp2 | The type of volume. Valid values are `standard`, `gp2` and `io1`. |
| 43 | +`enable_monitoring` | string | | Flag to enable detailed monitoring. |
| 44 | +`iam_path` | string | Default: / | The path to the IAM resource. |
| 45 | +`instance_based_naming_enabled` | string | | Flag to enable instance-id based name tagging. Requires the AWS CLI to be installed on the instance. Currently only supports Linux based systems. |
| 46 | +`instance_name_prefix` | string | | String to prepend instance-id based name tags with. |
| 47 | +`instance_tags` | map | | Map of tags to add to instances. Requires the AWS CLI to be installed on the instance. Currently only supports Linux based systems. |
| 48 | +`instance_type` | string | yes | The EC2 instance type to associate with the launch configuration. |
| 49 | +`key_name` | string | | The SSH key pair to associate with the launch configuration. |
| 50 | +`logs_bucket_enabled` | string | Default: false | Flag for enabling access to the logs bucket from the instances. |
| 51 | +`logs_bucket_name` | string | | Name of the S3 bucket for logging. |
| 52 | +`placement_tenancy` | string | Default: default | The tenancy of the instance. Valid values are `default` or `dedicated`. |
| 53 | +`root_vol_del_on_term` | string | Default: true | Whether the volume should be destroyed on instance termination. |
| 54 | +`root_vol_iops` | string | Default: 2000 | The amount of provisioned IOPS. Only utilized with `root_vol_type` of `io1`. |
| 55 | +`root_vol_size` | string | | The size of the volume in gigabytes. |
| 56 | +`root_vol_type` | string | Default: gp2 | The type of volume. Valid values are `standard`, `gp2` and `io1`. |
| 57 | +`security_groups` | list | Default: [] | A list of security group IDs to associate with the instances. |
| 58 | +`spot_price` | string | | The price to use for reserving spot instances. |
| 59 | +`user_data_override` | string | | Custom instance initialization data to associate with the launch configuration. |
| 60 | + |
| 61 | +#### Cluster auto scaling group parameters |
| 62 | +Name | Type | Required | Description |
58 | 63 | --- | --- | --- | ---
|
59 |
| -`agent_role_name` | string | | Name of the IAM role to be associated with the cluster members. |
60 |
| -`ami` | string | | Amazon Machine Image (AMI) of the cluster host. |
61 |
| -`cluster_name` | string | | Name of the ECS based application stack. |
62 |
| -`domain` | string | "" | The suffix domain name. |
63 |
| -`ecs_config` | string | "" | ECS agent configuration. |
64 |
| -`hc_check_type` | string | EC2 | Type of health check performed by the cluster. Valid values are 'ELB' or 'EC2'. |
65 |
| -`hc_grace_period` | string | 420 | Time allowed after an instance comes into service before checking health. |
66 |
| -`instance_type` | string | t2.small | EC2 instance type to associate with the cluster members. |
67 |
| -`key_name` | string | | SSH key pair to associate with the cluster members. |
68 |
| -`max_size` | string | 3 | Maximum number of instances allowed by the cluster. |
69 |
| -`min_size` | string | 3 | Minimum number of instances allowed by the cluster. |
70 |
| -`region` | string | us-east-1 | AWS region to be utilized. |
71 |
| -`stack_item_fullname` | string | | Long form descriptive name for this stack item. This value is used to create the 'application' resource tag for resources created by this stack item. |
72 |
| -`stack_item_label` | string | | Short form identifier for this stack. This value is used to create the 'Name' resource tag for resources created by this stack item, and also serves as a unique key for re-use. |
73 |
| -`subnets` | string | | List of VPC subnets to associate with the auto scaling group. |
74 |
| -`user_data` | string | "" | Instance initialization data to associate with the cluster members. |
75 |
| -`vpc_id` | string | | ID of the target VPC. |
| 64 | +`default_cooldown` | string | | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. |
| 65 | +`desired_capacity` | string | | The number of Amazon EC2 instances that should be running in the group. |
| 66 | +`enabled_metrics` | string | Default: [] | A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances`. |
| 67 | +`force_delete` | string | Default: false | Flag to allow deletion of the auto scaling group without waiting for all instances in the pool to terminate. |
| 68 | +`hc_check_type` | string | | Type of health check performed by the auto scaling group. Valid values are `ELB` or `EC2`. |
| 69 | +`hc_grace_period` | string | | Time allowed after an instance comes into service before checking health. |
| 70 | +`max_size` | string | yes | The maximum number of instances allowed by the auto scaling group. |
| 71 | +`min_size` | string | yes | Minimum number of instance to be maintained by the auto scaling group. |
| 72 | +`placement_group` | string | | The name of the placement group into which you'll launch your instances, if any. |
| 73 | +`protect_from_scale_in` | string | | Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events. |
| 74 | +`suspended_processes` | list | Default: [] | A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly. |
| 75 | +`termination_policies` | list | Default: [] | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default`. |
| 76 | +`wait_for_capacity_timeout` | string | | A maximum duration that Terraform should wait for ASG managed instances to become healthy before timing out. |
76 | 77 |
|
77 | 78 | ### Usage ###
|
78 | 79 |
|
79 | 80 | ```js
|
80 | 81 | module "cluster" {
|
81 | 82 | source = "github.com/unifio/terraform-aws-ecs?ref=master//cluster"
|
82 | 83 |
|
83 |
| - agent_role_name = "ecs" |
84 |
| - ami = "ami-xxxxxxxx" |
| 84 | + # Resource tags |
85 | 85 | cluster_name = "xmpl-prod"
|
86 |
| - domain = "service.consul" |
87 |
| - instance_type = "t2.small" |
88 |
| - key_name = "xmplprd" |
89 |
| - max_size = "3" |
90 |
| - min_size = "3" |
91 |
| - region = "us-east-1" |
92 | 86 | stack_item_fullname = "Example Cluster"
|
93 | 87 | stack_item_label = "xmpl"
|
94 |
| - subnets = "subnet-aaaaaaaa,subnet-bbbbbbbb,subnet-cccccccc" |
95 |
| - vpc_id = "vpc-xxxxxxxx" |
| 88 | + |
| 89 | + # VPC parameters |
| 90 | + subnets = ["subnet-aaaaaaaa","subnet-bbbbbbbb","subnet-cccccccc"] |
| 91 | + vpc_id = "vpc-xxxxxxxx" |
| 92 | + |
| 93 | + # LC parameters |
| 94 | + iam_path = "/tf_managed/" |
| 95 | + instance_based_naming_enabled = "true" |
| 96 | + instance_type = "t2.small" |
| 97 | + |
| 98 | + # ASG parameters |
| 99 | + max_size = "3" |
| 100 | + min_size = "3" |
96 | 101 | }
|
97 | 102 | ```
|
98 | 103 |
|
99 | 104 | ### Outputs ###
|
100 | 105 |
|
101 | 106 | Name | Type | Description
|
102 | 107 | --- | --- | --- | ---
|
103 |
| -`cluster_id` | string | ID of the ECS cluster |
104 |
| -`cluster_name` | string | Name of the ECS cluster |
| 108 | +`agent_role_id` | string | ID of the ECS agent IAM role. |
| 109 | +`cluster_id` | string | ID of the ECS cluster. |
| 110 | +`cluster_name` | string | Name of the ECS cluster. |
105 | 111 | `sg_id` | string | ID of the security group associated with the agent instances.
|
106 | 112 |
|
107 | 113 | ## Examples ##
|
|
0 commit comments