Skip to content

Commit 993551e

Browse files
Fixed CIDR block
1 parent 98b29ba commit 993551e

File tree

10 files changed

+36
-16
lines changed

10 files changed

+36
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ No resources.
136136
| <a name="input_alb"></a> [alb](#input\_alb) | Configuration settings for the Application Load Balancer (ALB). This includes attributes related to the ALB itself, such as its name, port, protocol, and other optional settings like access logs and tags. | <pre>object({<br/> name = optional(string, null)<br/> port = optional(number)<br/> protocol = optional(string, "HTTP")<br/> internal = optional(bool, false)<br/> load_balancer_type = optional(string, "application")<br/> idle_timeout = optional(number, 60)<br/> enable_deletion_protection = optional(bool, false)<br/> enable_http2 = optional(bool, true)<br/> certificate_arn = optional(string, null)<br/><br/> access_logs = optional(object({<br/> bucket = string<br/> enabled = optional(bool, false)<br/> prefix = optional(string, "")<br/> }))<br/><br/> tags = optional(map(string), {})<br/> })</pre> | n/a | yes |
137137
| <a name="input_alb_target_group"></a> [alb\_target\_group](#input\_alb\_target\_group) | List of target groups to create | <pre>list(object({<br/> name = optional(string, "target-group")<br/> port = number<br/> protocol = optional(string, null)<br/> protocol_version = optional(string, "HTTP1")<br/> vpc_id = optional(string, "")<br/> target_type = optional(string, "ip")<br/> ip_address_type = optional(string, "ipv4")<br/> load_balancing_algorithm_type = optional(string, "round_robin")<br/> load_balancing_cross_zone_enabled = optional(string, "use_load_balancer_configuration")<br/> deregistration_delay = optional(number, 300)<br/> slow_start = optional(number, 0)<br/> tags = optional(map(string), {})<br/><br/> health_check = optional(object({<br/> enabled = optional(bool, true)<br/> protocol = optional(string, "HTTP")<br/> path = optional(string, "/")<br/> port = optional(string, "traffic-port")<br/> timeout = optional(number, 6)<br/> healthy_threshold = optional(number, 3)<br/> unhealthy_threshold = optional(number, 3)<br/> interval = optional(number, 30)<br/> matcher = optional(string, "200")<br/> }))<br/><br/> stickiness = optional(object({<br/> enabled = optional(bool, true)<br/> type = string<br/> cookie_duration = optional(number, 86400)<br/> })<br/> )<br/><br/> }))</pre> | n/a | yes |
138138
| <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/> default_capacity_provider_use_fargate = bool<br/> fargate_capacity_providers = any<br/> })</pre> | n/a | yes |
139+
| <a name="input_cidr_blocks"></a> [cidr\_blocks](#input\_cidr\_blocks) | CIDR blocks for security group ingress rules | `list(string)` | <pre>[<br/> "0.0.0.0/0"<br/>]</pre> | no |
139140
| <a name="input_create_alb"></a> [create\_alb](#input\_create\_alb) | Flag to create or skip the creation of ALB | `bool` | `false` | no |
140141
| <a name="input_create_service"></a> [create\_service](#input\_create\_service) | Flag to create or skip the creation of ECS demo service | `bool` | `false` | no |
141142
| <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 = string<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 = bool<br/> service_connect_defaults = optional(map(string), null)<br/> settings = optional(any, null)<br/> tags = optional(map(string), null)<br/> })</pre> | n/a | yes |

docs/module-usage-guide/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This document provides guidelines and instructions for users looking to implemen
1010

1111
The [Terraform AWS ARC ECS](https://github.com/sourcefuse/terraform-aws-arc-ecs) module provides a secure and modular foundation for deploying ECS clusters on AWS.
1212

13+
The Module assumes there is a docker image present on ECR which will serve as ECS service if the optional ECS module is called.
14+
1315
### Prerequisites
1416

1517
Before using this module, ensure you have the following:

example/main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module "ecs_cluster" {
2323
##########################################
2424
## Flags for ALB and service modules
2525
##########################################
26-
create_alb = false
27-
create_service = false
26+
create_alb = true
27+
create_service = true
2828

2929
#####################
3030
## ecs cluster
@@ -72,22 +72,24 @@ module "ecs_cluster" {
7272

7373
task = {
7474
tasks_desired = 1
75-
container_port = 8100
75+
container_port = 80
7676
container_memory = 1024
7777
container_vcpu = 256
7878
container_definition = "container/container_definition.json.tftpl"
7979
}
8080

8181
lb = {
8282
name = "arc-poc-alb"
83-
listener_port = 8100
84-
security_group_id = ""
83+
listener_port = 80
84+
security_group_id = "sg-12345"
8585
}
8686

8787
#####################
8888
## ALB
8989
#####################
9090

91+
cidr_blocks = null
92+
9193
alb = {
9294
name = "arc-poc-alb"
9395
internal = false
@@ -98,7 +100,7 @@ module "ecs_cluster" {
98100
name = "arc-poc-alb-tg"
99101
port = 80
100102
protocol = "HTTP"
101-
vpc_id = "vpc-123445"
103+
vpc_id = "vpc-12345"
102104
target_type = "ip"
103105
health_check = {
104106
enabled = true

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module "alb" {
2929
count = var.create_alb ? 1 : 0
3030
source = "./modules/alb"
3131

32-
vpc_id = var.vpc_id
32+
vpc_id = var.vpc_id
33+
cidr_blocks = var.cidr_blocks
34+
3335

3436
alb = {
3537
name = var.alb.name

modules/alb/data.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ data "aws_subnet" "public" {
1212

1313
id = each.value
1414
}
15+
16+
# To get VPC CIDR for ALB security group as default ingress
17+
data "aws_vpc" "this" {
18+
id = var.vpc_id
19+
}

modules/alb/locals.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ locals {
44
for s in data.aws_subnet.public :
55
s.id if lookup(s.tags, "Type", "") == "public"
66
]
7+
8+
cidr_blocks = var.cidr_blocks != null ? var.cidr_blocks : [data.aws_vpc.this.cidr_block]
9+
710
}

modules/alb/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ resource "aws_security_group" "lb_sg" {
2424
from_port = 80
2525
to_port = 80
2626
protocol = "tcp"
27-
cidr_blocks = var.cidr_blocks
27+
cidr_blocks = local.cidr_blocks
2828
}
2929

3030
ingress {
3131
from_port = 443
3232
to_port = 443
3333
protocol = "tcp"
34-
cidr_blocks = var.cidr_blocks
34+
cidr_blocks = local.cidr_blocks
3535
}
3636

3737
egress {

modules/alb/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ variable "vpc_id" {
1010
}
1111

1212
variable "cidr_blocks" {
13-
description = "CIDR blocks for security group ingress rules"
13+
description = "CIDR blocks for ALB security group ingress rules"
1414
type = list(string)
15-
default = ["0.0.0.0/0"]
15+
default = null
1616
}
1717

1818

modules/ecs_service/main.tf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ resource "aws_security_group" "ecs" {
7575
vpc_id = var.vpc_id
7676

7777
ingress {
78-
description = "Allow inbound proxy traffic"
79-
from_port = var.task.container_port
80-
to_port = var.task.container_port
81-
protocol = "tcp"
82-
#cidr_blocks = [for subnet in data.aws_subnet.private : subnet.cidr_block]
78+
description = "Allow inbound proxy traffic"
79+
from_port = var.task.container_port
80+
to_port = var.task.container_port
81+
protocol = "tcp"
8382
security_groups = [var.lb.security_group_id]
8483
}
8584

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ variable "vpc_id" {
8484
description = "ID of VPC in which all resources need to be created"
8585
}
8686

87+
variable "cidr_blocks" {
88+
description = "CIDR blocks for security group ingress rules"
89+
type = list(string)
90+
default = ["0.0.0.0/0"]
91+
}
92+
8793
variable "alb" {
8894
description = "Configuration settings for the Application Load Balancer (ALB). This includes attributes related to the ALB itself, such as its name, port, protocol, and other optional settings like access logs and tags."
8995
type = object({

0 commit comments

Comments
 (0)