Skip to content

Commit db99e2c

Browse files
committed
adding ec2
1 parent c5cb602 commit db99e2c

File tree

7 files changed

+84
-31
lines changed

7 files changed

+84
-31
lines changed

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,38 @@ In your main Terraform configuration file (e.g., main.tf), you can use the modul
5959

6060

6161
```hcl
62+
################################################################################
63+
## ecs cluster
64+
################################################################################
65+
6266
module "ecs_cluster" {
63-
source = "./modules/ecs_cluster"
64-
65-
ecs_cluster = {
66-
name = var.ecs_cluster.name
67-
configuration = var.ecs_cluster.configuration
68-
create_cloudwatch_log_group = var.ecs_cluster.create_cloudwatch_log_group
69-
service_connect_defaults = var.ecs_cluster.service_connect_defaults
70-
settings = var.ecs_cluster.settings
71-
}
72-
73-
capacity_provider = {
74-
autoscaling_capacity_providers = var.capacity_provider.autoscaling_capacity_providers
75-
default_capacity_provider_use_fargate = var.capacity_provider.default_capacity_provider_use_fargate
76-
fargate_capacity_providers = var.capacity_provider.fargate_capacity_providers
77-
}
67+
source = "../../"
68+
69+
ecs_cluster = local.ecs_cluster
70+
capacity_provider = local.capacity_provider
71+
ecs_service = local.ecs_service
72+
tags = module.tags.tags
73+
}
74+
75+
################################################################################
76+
## ecs services and task
77+
################################################################################
78+
79+
module "ecs_services" {
80+
for_each = local.ecs_services
81+
82+
source = "../../"
83+
ecs_cluster = each.value.ecs_cluster
84+
ecs_cluster_name = local.ecs_cluster.name
85+
ecs_service = each.value.ecs_service
86+
task = each.value.task
87+
lb_data = each.value.lb_data
88+
vpc_id = data.aws_vpc.default.id
89+
target_group_arn = module.alb.target_group_arn
90+
environment = var.environment
91+
tags = module.tags.tags
92+
depends_on = [module.ecs_cluster, module.alb]
93+
7894
}
7995
```
8096

@@ -133,9 +149,9 @@ No resources.
133149
|------|-------------|------|---------|:--------:|
134150
| <a name="input_asg"></a> [asg](#input\_asg) | Auto Scaling Group configuration | <pre>object({<br> name = optional(string, null)<br> min_size = number<br> max_size = number<br> desired_capacity = optional(number)<br> vpc_zone_identifier = optional(list(string))<br><br> health_check_type = optional(string)<br> health_check_grace_period = optional(number, 300)<br> protect_from_scale_in = optional(bool)<br> default_cooldown = optional(number)<br><br> instance_refresh = optional(object({<br> strategy = string<br> preferences = optional(object({<br> min_healthy_percentage = optional(number)<br> }))<br> }))<br> })</pre> | `null` | no |
135151
| <a name="input_capacity_provider"></a> [capacity\_provider](#input\_capacity\_provider) | Configuration settings for the ECS capacity providers, including the capacity providers used for autoscaling and Fargate. This variable defines the properties of each capacity provider and how they are managed, such as scaling policies and termination protection. | <pre>object({<br> autoscaling_capacity_providers = map(object({<br> name = optional(string)<br> auto_scaling_group_arn = string<br> managed_termination_protection = optional(string, "DISABLED")<br> managed_draining = optional(string, "ENABLED")<br> managed_scaling = optional(object({<br> instance_warmup_period = optional(number)<br> maximum_scaling_step_size = optional(number)<br> minimum_scaling_step_size = optional(number)<br> status = optional(string)<br> target_capacity = optional(number)<br> }))<br> tags = optional(map(string), {})<br> }))<br> use_fargate = bool<br> fargate_capacity_providers = any<br> })</pre> | `null` | no |
136-
| <a name="input_ecs_cluster"></a> [ecs\_cluster](#input\_ecs\_cluster) | The ECS-specific values to use such as cluster, service, and repository names.<br><br>Keys:<br> - cluster\_name: The name of the ECS cluster.<br> - cluster\_configuration: The execute command configuration for the cluster.<br> - cluster\_settings: A list of cluster settings (e.g., container insights). Default is an empty list.<br> - cluster\_service\_connect\_defaults: Configures a default Service Connect namespace.<br> - create\_cloudwatch\_log\_group: Boolean flag to specify whether to create a CloudWatch log group for the ECS cluster. | <pre>object({<br> name = optional(string)<br> create_cluster = optional(bool, true)<br> configuration = optional(object({<br> execute_command_configuration = optional(object({<br> kms_key_id = optional(string, "")<br> logging = optional(string, "DEFAULT")<br> log_configuration = optional(object({<br> cloudwatch_encryption_enabled = optional(bool, null)<br> log_group_name = optional(string, null)<br> log_group_retention_in_days = optional(number, null)<br> log_group_kms_key_id = optional(string, null)<br> log_group_tags = optional(map(string), null)<br> s3_bucket_name = optional(string, null)<br> s3_bucket_encryption_enabled = optional(bool, null)<br> s3_key_prefix = optional(string, null)<br> }), {})<br> }), {})<br> }), {})<br> create_cloudwatch_log_group = optional(bool, true)<br> service_connect_defaults = optional(map(string), null)<br> settings = optional(any, null)<br> tags = optional(map(string), null)<br> })</pre> | n/a | yes |
152+
| <a name="input_ecs_cluster"></a> [ecs\_cluster](#input\_ecs\_cluster) | The ECS-specific values to use such as cluster, service, and repository names.<br><br>Keys:<br> - cluster\_name: The name of the ECS cluster.<br> - cluster\_configuration: The execute command configuration for the cluster.<br> - cluster\_settings: A list of cluster settings (e.g., container insights). Default is an empty list.<br> - cluster\_service\_connect\_defaults: Configures a default Service Connect namespace.<br> - create\_cloudwatch\_log\_group: Boolean flag to specify whether to create a CloudWatch log group for the ECS cluster. | <pre>object({<br> name = optional(string)<br> create = optional(bool, true)<br> configuration = optional(object({<br> execute_command_configuration = optional(object({<br> kms_key_id = optional(string, "")<br> logging = optional(string, "DEFAULT")<br> log_configuration = optional(object({<br> cloudwatch_encryption_enabled = optional(bool, null)<br> log_group_name = optional(string, null)<br> log_group_retention_in_days = optional(number, null)<br> log_group_kms_key_id = optional(string, null)<br> log_group_tags = optional(map(string), null)<br> s3_bucket_name = optional(string, null)<br> s3_bucket_encryption_enabled = optional(bool, null)<br> s3_key_prefix = optional(string, null)<br> }), {})<br> }), {})<br> }), {})<br> create_cloudwatch_log_group = optional(bool, true)<br> service_connect_defaults = optional(map(string), null)<br> settings = optional(any, null)<br> tags = optional(map(string), null)<br> })</pre> | n/a | yes |
137153
| <a name="input_ecs_cluster_name"></a> [ecs\_cluster\_name](#input\_ecs\_cluster\_name) | Name of the ECS cluster | `string` | `null` | no |
138-
| <a name="input_ecs_service"></a> [ecs\_service](#input\_ecs\_service) | The ECS-specific values to use such as cluster, service, and repository names. | <pre>object({<br> cluster_name = optional(string)<br> service_name = optional(string)<br> repository_name = optional(string)<br> enable_load_balancer = optional(bool, false)<br> aws_lb_target_group_name = optional(string)<br> ecs_subnets = optional(list(string))<br> create_service = optional(bool, false)<br> })</pre> | n/a | yes |
154+
| <a name="input_ecs_service"></a> [ecs\_service](#input\_ecs\_service) | The ECS-specific values to use such as cluster, service, and repository names. | <pre>object({<br> cluster_name = optional(string)<br> service_name = optional(string)<br> repository_name = optional(string)<br> enable_load_balancer = optional(bool, false)<br> aws_lb_target_group_name = optional(string)<br> ecs_subnets = optional(list(string))<br> create = optional(bool, false)<br> })</pre> | n/a | yes |
139155
| <a name="input_environment"></a> [environment](#input\_environment) | The environment associated with the ECS service | `string` | `null` | no |
140156
| <a name="input_launch_template"></a> [launch\_template](#input\_launch\_template) | n/a | <pre>object({<br> name = string<br> block_device_mappings = optional(list(object({<br> device_name = string<br> ebs = optional(object({<br> volume_size = number<br> }))<br> })), [])<br><br> cpu_options = optional(object({<br> core_count = number<br> threads_per_core = number<br> }), null)<br><br> disable_api_stop = optional(bool, false)<br> disable_api_termination = optional(bool, false)<br> ebs_optimized = optional(bool, false)<br><br> elastic_gpu_specifications = optional(list(object({<br> type = string<br> })), [])<br><br> iam_instance_profile = optional(object({<br> name = string<br> }), null)<br><br> image_id = optional(string, null)<br> instance_initiated_shutdown_behavior = optional(string, "stop")<br><br> instance_type = optional(string, null)<br> kernel_id = optional(string, null)<br> key_name = optional(string, null)<br><br> monitoring = optional(object({<br> enabled = bool<br> }), null)<br><br> network_interfaces = optional(list(object({<br> associate_public_ip_address = optional(bool, null)<br> ipv4_prefixes = optional(list(string), [])<br> ipv6_prefixes = optional(list(string), [])<br> ipv4_addresses = optional(list(string), [])<br> ipv6_addresses = optional(list(string), [])<br> network_interface_id = optional(string, null)<br> private_ip_address = optional(string, null)<br> security_groups = optional(list(string), [])<br> subnet_id = optional(string, null)<br> })), [])<br><br> placement = optional(object({<br> availability_zone = string<br> }), null)<br><br> vpc_security_group_ids = optional(list(string), [])<br><br> tag_specifications = optional(list(object({<br> resource_type = string<br> tags = map(string)<br> })), [])<br><br> user_data = optional(string, null)<br> })</pre> | `null` | no |
141157
| <a name="input_lb_data"></a> [lb\_data](#input\_lb\_data) | ALB-related information (listening port, deletion protection, security group) | <pre>object({<br> listener_port = number<br> deregistration_delay = optional(number)<br> security_group_id = optional(string)<br> })</pre> | `null` | no |

docs/module-usage-guide/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,33 @@ Before using this module, ensure you have the following:
2727
To use the module in your Terraform configuration, include the following source block:
2828

2929
```hcl
30+
31+
##########################################
32+
## ecs cluster with ec2
33+
##########################################
3034
module "arc-ecs" {
3135
source = "sourcefuse/arc-ecs/aws"
3236
version = "1.5.0"
33-
# insert the 6 required variables here
37+
ecs_cluster = local.ecs_cluster
38+
capacity_provider = local.capacity_provider
39+
ecs_service = local.ecs_service
40+
launch_template = local.launch_template
41+
asg = local.asg
42+
tags = module.tags.tags
43+
}
44+
45+
##########################################
46+
## ecs cluster with fargate
47+
##########################################
48+
module "ecs_cluster" {
49+
source = "sourcefuse/arc-ecs/aws"
50+
version = "1.5.0"
51+
ecs_cluster = local.ecs_cluster
52+
capacity_provider = local.capacity_provider
53+
ecs_service = local.ecs_service
54+
tags = module.tags.tags
3455
}
56+
3557
```
3658

3759
Refer to the [Terraform Registry](https://registry.terraform.io/modules/sourcefuse/arc-ecs/aws/latest) for the latest version.
@@ -41,7 +63,7 @@ Refer to the [Terraform Registry](https://registry.terraform.io/modules/sourcefu
4163
Integrate the module with your existing Terraform mono repo configuration, follow the steps below:
4264

4365
1. Create a new folder in `terraform/` named `ecs`.
44-
2. Create the required files, see the [examples](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/example) to base off of.
66+
2. Create the required files, see the [examples](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/examples) to base off of.
4567
3. Configure with your backend
4668
- Create the environment backend configuration file: `config.<environment>.hcl`
4769
- **region**: Where the backend resides
@@ -74,7 +96,7 @@ For a list of outputs, see the README [Outputs](https://github.com/sourcefuse/te
7496

7597
### Basic Usage
7698

77-
For basic usage, see the [example](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/example) folder.
99+
For basic usage, see the [example](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/examples) folder.
78100

79101
This example will create:
80102

examples/ecs-ec2/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module "tags" {
2828
}
2929
}
3030

31+
################################################################################
32+
## ecs cluster
33+
################################################################################
34+
3135
module "ecs_cluster" {
3236
source = "../../"
3337

@@ -39,6 +43,10 @@ module "ecs_cluster" {
3943
tags = module.tags.tags
4044
}
4145

46+
################################################################################
47+
## ecs services and task
48+
################################################################################
49+
4250
module "ecs_services" {
4351
for_each = local.ecs_services
4452

examples/ecs-fargate/locals.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ locals {
33

44
ecs_cluster = {
55
name = "arc-ecs-fargate-poc"
6-
create_cluster = true
6+
create = true
77
create_cloudwatch_log_group = true
88
service_connect_defaults = {}
99
settings = []
@@ -28,15 +28,15 @@ locals {
2828
}
2929
}
3030
ecs_service = {
31-
create_service = false
31+
create = false
3232
}
3333

3434
############################### ECS Services ################################
3535

3636
ecs_services = {
3737
service1 = {
3838
ecs_cluster = {
39-
create_cluster = false
39+
create = false
4040
}
4141
ecs_service = {
4242
cluster_name = "arc-ecs-module-poc-1"
@@ -45,7 +45,7 @@ locals {
4545
ecs_subnets = data.aws_subnets.private.ids
4646
enable_load_balancer = true
4747
aws_lb_target_group_name = "arc-poc-alb-tg"
48-
create_service = true
48+
create = true
4949
}
5050

5151
task = {
@@ -67,7 +67,7 @@ locals {
6767

6868
service2 = { # FIXED: Changed from duplicate "service1" to "service2"
6969
ecs_cluster = {
70-
create_cluster = false
70+
create = false
7171
}
7272
ecs_service = {
7373
cluster_name = "arc-ecs-module-poc-2"
@@ -76,7 +76,7 @@ locals {
7676
ecs_subnets = data.aws_subnets.private.ids
7777
enable_load_balancer = true
7878
aws_lb_target_group_name = "arc-poc-alb-tg"
79-
create_service = true
79+
create = true
8080
}
8181

8282
task = {

examples/ecs-fargate/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ module "tags" {
2828
}
2929
}
3030

31+
################################################################################
32+
## ecs cluster
33+
################################################################################
3134

3235
module "ecs_cluster" {
3336
source = "../../"
@@ -38,6 +41,10 @@ module "ecs_cluster" {
3841
tags = module.tags.tags
3942
}
4043

44+
################################################################################
45+
## ecs services and task
46+
################################################################################
47+
4148
module "ecs_services" {
4249
for_each = local.ecs_services
4350

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module "ecs_cluster" {
66
source = "./modules/ecs-cluster"
7-
count = var.ecs_cluster.create_cluster ? 1 : 0
7+
count = var.ecs_cluster.create ? 1 : 0
88
ecs_cluster = {
99
name = var.ecs_cluster.name
1010
configuration = var.ecs_cluster.configuration
@@ -29,7 +29,7 @@ module "ecs_cluster" {
2929
################################################################################
3030

3131
module "ecs_service" {
32-
count = var.ecs_service.create_service ? 1 : 0
32+
count = var.ecs_service.create ? 1 : 0
3333
source = "./modules/ecs-service"
3434

3535
vpc_id = var.vpc_id

variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ variable "tags" {
99

1010
variable "ecs_cluster" {
1111
type = object({
12-
name = optional(string)
13-
create_cluster = optional(bool, true)
12+
name = optional(string)
13+
create = optional(bool, true)
1414
configuration = optional(object({
1515
execute_command_configuration = optional(object({
1616
kms_key_id = optional(string, "")
@@ -188,7 +188,7 @@ variable "ecs_service" {
188188
enable_load_balancer = optional(bool, false)
189189
aws_lb_target_group_name = optional(string)
190190
ecs_subnets = optional(list(string))
191-
create_service = optional(bool, false)
191+
create = optional(bool, false)
192192
})
193193
description = "The ECS-specific values to use such as cluster, service, and repository names."
194194
}

0 commit comments

Comments
 (0)