Skip to content

Commit 195878e

Browse files
Merge pull request #7 from gaussb-labs/feature/update-readme
docs: update readme
2 parents 3b13274 + 2c877b0 commit 195878e

File tree

2 files changed

+175
-6
lines changed

2 files changed

+175
-6
lines changed

README.md

Lines changed: 171 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,173 @@
1-
### ECS Terraform Module
1+
## ECS Cluster Terraform Module
22

3-
This module provides resources for the setup of ECS cluster. This includes:
3+
Terraform module which creates Amazon ECS cluster with EC2 launch type
44

5-
- ECS cluster
6-
- Capacity Providers
7-
- Auto scaling groups
8-
- Launch Configurations
5+
This module creates following resources:
6+
7+
1. ECS cluster
8+
2. Capacity providers
9+
3. Autoscaling groups for EC2
10+
4. Launch configuration for EC2
11+
12+
![](./diagram.svg)
13+
14+
15+
### Usage
16+
```hcl
17+
module "app_cluster" {
18+
source = "git::https://github.com/gaussb-labs/terraform-aws-ecs-cluster-module.git?ref=v1.1.2"
19+
environment = "production"
20+
cluster_name = "app_cluster"
21+
launch_configs = [
22+
{
23+
name = "java_application"
24+
image_id = "ami-040d909ea4e56f8f3"
25+
instance_type = "t3a.medium"
26+
user_data_base64 = ""
27+
iam_instance_profile_name = "ecs_agent_access_instance_profile"
28+
security_group_ids = ["sg-01", "sg-02"]
29+
},
30+
{
31+
name = "rails_application"
32+
image_id = "ami-040d909ea4e56f8f3"
33+
instance_type = "t3a.medium"
34+
user_data_base64 = ""
35+
iam_instance_profile_name = "ecs_agent_access_instance_profile"
36+
security_group_ids = ["sg-03", "sg-04"]
37+
}
38+
]
39+
asg = [
40+
{
41+
name = "java_application"
42+
vpc_zone_identifier = ["subnet_id_1", "subnet_id_2"]
43+
health_check_type = "EC2"
44+
health_check_grace_period = 10
45+
max_size = 3
46+
min_size = 1
47+
protect_from_scale_in = true
48+
additional_tags = []
49+
},
50+
{
51+
name = "rails_application"
52+
vpc_zone_identifier = ["subnet_id_1", "subnet_id_2"]
53+
health_check_type = "EC2"
54+
health_check_grace_period = 10
55+
max_size = 2
56+
min_size = 0
57+
protect_from_scale_in = false
58+
additional_tags = []
59+
}
60+
]
61+
capacity_providers = [
62+
{
63+
name = "java_application"
64+
target_capacity = 100
65+
managed_scaling_status = "ENABLED"
66+
managed_termination_protection = "ENABLED"
67+
},
68+
{
69+
name = "rails_application"
70+
target_capacity = 100
71+
managed_scaling_status = "ENABLED"
72+
managed_termination_protection = "DISABLED"
73+
}
74+
]
75+
}
76+
```
77+
78+
_NOTE:_</br>
79+
_This module doesn't provide the ability to create ECS services and tasks.
80+
This can be created separately and should be closer to the application deployments
81+
rather than the infrastructure deployments._
82+
83+
### Configuration
84+
#### 1. asg
85+
asg is a list of auto-scaling group configuration. This module supports
86+
multiple asg configurations per cluster. This is useful in scenarios where
87+
we need different auto-scaling for different kind of workloads.
88+
`launch_config` is required for auto-scaling group.
89+
90+
91+
#### 2. launch_configs
92+
launch_configs is a list of launch configurations, used by the auto-scaling groups
93+
to spin up new EC2 instances. One launch configuration per auto-scaling group is
94+
supported, although we can specify multiple launch configurations if there are multiple
95+
auto-scaling groups defined.
96+
The launch configuration is linked to the auto-scaling group via the `name` attribute,
97+
so name has to same for both asg and launch configuration.
98+
99+
_`iam_instance_profile_name` is expected by this module. The instance_profile should be created considering
100+
the accesses needed by the ECS agent to interact with the ECS cluster and service._
101+
102+
103+
#### 3. capacity_providers
104+
Configuration block for defining capacity providers in the ECS cluster.
105+
This is needed if you plan to use capacity provider strategy for ECS service.
106+
`asg` and `launch_config` are required for the capacity provider.
107+
108+
109+
## Requirements
110+
111+
| Name | Version |
112+
|------|---------|
113+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | \>= 1.2.0 |
114+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.16 |
115+
| <a name="requirement_cloudinit"></a> [cloudinit](#requirement\_cloudinit) | \>=2.2.0 |
116+
117+
## Providers
118+
119+
| Name | Version |
120+
|------|---------|
121+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.16 |
122+
123+
## Modules
124+
125+
No modules.
126+
127+
## Resources
128+
129+
| Name | Type |
130+
|------|------|
131+
| [aws_autoscaling_group.ecs_cluster_asg](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group) | resource |
132+
| [aws_ecs_capacity_provider.capacity_providers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_capacity_provider) | resource |
133+
| [aws_ecs_cluster.ecs_cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster) | resource |
134+
| [aws_ecs_cluster_capacity_providers.ecs_cluster_capacity_provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster_capacity_providers) | resource |
135+
| [aws_launch_configuration.ecs_launch_config](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_configuration) | resource |
136+
137+
### Inputs
138+
139+
| Name | Description | Type | Default | Required |
140+
|--------------------------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------- |---------------- |--------- |---------- |
141+
| environment | The cluster deployment environment. environment is added as prefix to the resources generated by this module. | `string` | n/a | yes |
142+
| cluster_name | Name of ECS cluster. environment is not added to the cluster name. | `string` | n/a | yes |
143+
| capacity_providers | List of capacity provider configuration. | `list(object)` | n/a | yes |
144+
| capacity_providers.name | Capacity provider name. This is used by the module to link auto-scaling group, launch configuration and capacity provider. | `string` | n/a | yes |
145+
| capacity_providers.target_capacity | Target utilisation for the capacity provider. A value between 1 and 100. | `number` | n/a | yes |
146+
| capacity_providers.managed_scaling_status | Whether auto-scaling is managed by ECS. Valid values are `ENABLED` and `DISABLED`. | `string` | n/a | yes |
147+
| capacity_providers.managed_termination_protection | Manage container-aware termination of instances in the auto scaling group when scale-in happens. Valid values are `ENABLED` and `DISABLED`. | `string` | n/a | yes |
148+
| asg | List of auto-scaling group configuration. | `list(object)` | n/a | yes |
149+
| asg.name | Name of auto-scaling group. | `string` | n/a | yes |
150+
| asg.vpc_zone_identifier | List of subnet Ids to launch resources in. | `list(string)` | n/a | yes |
151+
| asg.health_check_type | Controls how health check is done. Valid values are `EC2` and `ELB`. | `string` | n/a | yes |
152+
| asg.health_check_grace_period | Time in seconds after instance comes up and health check first kicks in. | `number` | n/a | yes |
153+
| asg.max_size | The maximum capacity auto-scaling group can scale-out to. | `number` | n/a | yes |
154+
| asg.min_size | The minimum capacity auto-scaling group can scale-in to. | `number` | n/a | yes |
155+
| asg.protect_from_scale_in | Indicates whether newly launched instances are automatically protected from termination by auto-scaling group when scaling in. | `bool` | n/a | yes |
156+
| asg.additional_tags | List of additional tags. | `list(object)` | n/a | yes |
157+
| asg.additional_tags.key | Key of the tag. | `string` | n/a | yes |
158+
| asg.additional_tags.value | Value of the tag. | `string` | n/a | yes |
159+
| asg.additional_tags.propagate_at_launch | Indicates whether to propagate the tag to the newly launched EC2 instances. | `bool` | n/a | yes |
160+
| launch_configs | List of launch configurations for auto-scaling groups. | `list(object)` | n/a | yes |
161+
| launch_configs.name | Name of the launch configuration. Should be same as corresponding auto-scaling group name. | `string` | n/a | yes |
162+
| launch_configs.image_id | AMI Id of the image to use. | `string` | n/a | yes |
163+
| launch_configs.instance_type | The type of EC2 instance to use. Eg: t3.small | `string` | n/a | yes |
164+
| launch_configs.user_data_base64 | Base64 encoded userdata. | `string` | n/a | yes |
165+
| launch_configs.iam_instance_profile_name | Name of the IAM instance profile to attach to the EC2 instance. | `string` | n/a | yes |
166+
| launch_configs.security_group_ids | List of security group ids to attach to the EC2 instance. | `list(string)` | n/a | yes |
167+
168+
169+
### Outputs
170+
No outputs.
171+
172+
### License
173+
MIT Licensed. See [LICENSE](https://github.com/gaussb-labs/terraform-aws-ecs-cluster-module/blob/main/LICENSE) for full details.

0 commit comments

Comments
 (0)