Skip to content

Commit 5449c79

Browse files
patrickmukumbuboldlinksig
andauthored
feat: showcased load balancer association with WAF ACL (#35)
* feat: showcased load balancer association with WAF ACL * [Boldlinksig]: Pre-commit auto updated files on 10-11-2023 17:05:43. * Modified changelog release number --------- Co-authored-by: boldlinksig <boldlinksig@boldlink.io>
1 parent fab7367 commit 5449c79

File tree

10 files changed

+148
-10
lines changed

10 files changed

+148
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- feat: Add missing aws_ecs_task_definition arguments and showcase them in examples
2727
- feat: expand volume block of the task definition as it has more configuration
2828

29-
## [1.7.0] - 2023-12-03
29+
## [1.8.0] - 2023-11-10
30+
### Changes
31+
- feat: Showcased WAF association for the loadbalancer
32+
33+
## [1.7.0] - 2023-11-03
3034
### Changes
3135
- feat: add complete example for alb and nlb service
3236
- feat: Enable ALB idle timeout configuration - this feature only works with ALB and not NLB.
@@ -142,8 +146,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
142146
- feat: feature update.
143147
- feat: initial code commit
144148

145-
[Unreleased]: https://github.com/boldlink/terraform-aws-ecs-service/compare/1.7.0...HEAD
149+
[Unreleased]: https://github.com/boldlink/terraform-aws-ecs-service/compare/1.7.1...HEAD
146150

151+
[1.7.1]: https://github.com/boldlink/terraform-aws-ecs-service/releases/tag/1.7.1
147152
[1.7.0]: https://github.com/boldlink/terraform-aws-ecs-service/releases/tag/1.7.0
148153
[1.6.0]: https://github.com/boldlink/terraform-aws-ecs-service/releases/tag/1.6.0
149154
[1.5.3]: https://github.com/boldlink/terraform-aws-ecs-service/releases/tag/1.5.3

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ module "ecs_service" {
186186

187187
| Name | Version |
188188
|------|---------|
189-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.24.0 |
189+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
190190
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.0.4 |
191191

192192
## Modules
@@ -235,7 +235,7 @@ No modules.
235235
|------|-------------|------|---------|:--------:|
236236
| <a name="input_access_logs"></a> [access\_logs](#input\_access\_logs) | (Optional) Define an Access Logs block | `map(string)` | `{}` | no |
237237
| <a name="input_acm_certificate_arn"></a> [acm\_certificate\_arn](#input\_acm\_certificate\_arn) | ARN of ACM generated/third party certificate | `string` | `null` | no |
238-
| <a name="input_adjustment_type"></a> [adjustment\_type](#input\_adjustment\_type) | Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity. | `string` | `"ChangeInCapacity"` | no |
238+
| <a name="input_adjustment_type"></a> [adjustment\_type](#input\_adjustment\_type) | (Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity. | `string` | `"ChangeInCapacity"` | no |
239239
| <a name="input_alb_subnets"></a> [alb\_subnets](#input\_alb\_subnets) | Subnet IDs for the application load balancer. | `list(string)` | `[]` | no |
240240
| <a name="input_associate_with_waf"></a> [associate\_with\_waf](#input\_associate\_with\_waf) | Whether to associate created ALB with AWS WAFv2 ACL | `bool` | `false` | no |
241241
| <a name="input_associate_with_wafregional"></a> [associate\_with\_wafregional](#input\_associate\_with\_wafregional) | Whether to associate created ALB with WAF Regional Web ACL | `bool` | `false` | no |

examples/complete/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To test the deployment, follow these steps:
3939

4040
| Name | Version |
4141
|------|---------|
42-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.24.0 |
42+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
4343

4444
## Modules
4545

@@ -48,6 +48,7 @@ To test the deployment, follow these steps:
4848
| <a name="module_access_logs_bucket"></a> [access\_logs\_bucket](#module\_access\_logs\_bucket) | boldlink/s3/aws | 2.3.1 |
4949
| <a name="module_ecs_service_alb"></a> [ecs\_service\_alb](#module\_ecs\_service\_alb) | ../../ | n/a |
5050
| <a name="module_ecs_service_nlb"></a> [ecs\_service\_nlb](#module\_ecs\_service\_nlb) | ../../ | n/a |
51+
| <a name="module_waf_acl"></a> [waf\_acl](#module\_waf\_acl) | boldlink/waf/aws | 1.0.3 |
5152

5253
## Resources
5354

@@ -74,9 +75,12 @@ To test the deployment, follow these steps:
7475
|------|-------------|------|---------|:--------:|
7576
| <a name="input_access_logs_enabled"></a> [access\_logs\_enabled](#input\_access\_logs\_enabled) | Whether to enable access logs for the lb | `bool` | `true` | no |
7677
| <a name="input_alb_ingress_rules"></a> [alb\_ingress\_rules](#input\_alb\_ingress\_rules) | Incoming traffic configuration for the load balancer security group | `list(any)` | <pre>[<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": "Allow traffic to load balancer on port 443",<br> "from_port": 443,<br> "protocol": "tcp",<br> "to_port": 443<br> },<br> {<br> "cidr_blocks": [<br> "0.0.0.0/0"<br> ],<br> "description": "Allow traffic to alb load balancer on port 80",<br> "from_port": 80,<br> "protocol": "tcp",<br> "to_port": 80<br> }<br>]</pre> | no |
78+
| <a name="input_cloudwatch_metrics_enabled"></a> [cloudwatch\_metrics\_enabled](#input\_cloudwatch\_metrics\_enabled) | Whether to enable cloudwatch metrics | `bool` | `false` | no |
7779
| <a name="input_containerport"></a> [containerport](#input\_containerport) | Specify container port | `number` | `5000` | no |
7880
| <a name="input_cpu"></a> [cpu](#input\_cpu) | The number of cpu units to allocate | `number` | `10` | no |
7981
| <a name="input_create_load_balancer"></a> [create\_load\_balancer](#input\_create\_load\_balancer) | Whether to create a load balancer for ecs. | `bool` | `true` | no |
82+
| <a name="input_custom_header_name"></a> [custom\_header\_name](#input\_custom\_header\_name) | The name of the custom header to insert | `string` | `"X-My-Company-Tracking-ID"` | no |
83+
| <a name="input_custom_header_value"></a> [custom\_header\_value](#input\_custom\_header\_value) | The value of the custom header to insert | `string` | `"1234567890"` | no |
8084
| <a name="input_drop_invalid_header_fields"></a> [drop\_invalid\_header\_fields](#input\_drop\_invalid\_header\_fields) | Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (true) or routed to targets (false). | `bool` | `true` | no |
8185
| <a name="input_enable_autoscaling"></a> [enable\_autoscaling](#input\_enable\_autoscaling) | Whether to enable autoscaling or not for ecs | `bool` | `true` | no |
8286
| <a name="input_enable_execute_command"></a> [enable\_execute\_command](#input\_enable\_execute\_command) | value to enable execute command at the ecs service, default = false | `bool` | `true` | no |
@@ -92,6 +96,7 @@ To test the deployment, follow these steps:
9296
| <a name="input_path"></a> [path](#input\_path) | Destination for the health check request. Required for HTTP/HTTPS ALB and HTTP NLB. Only applies to HTTP/HTTPS. | `string` | `"/healthz"` | no |
9397
| <a name="input_requires_compatibilities"></a> [requires\_compatibilities](#input\_requires\_compatibilities) | Set of launch types required by the task. The valid values are EC2 and FARGATE. | `list(string)` | <pre>[<br> "FARGATE"<br>]</pre> | no |
9498
| <a name="input_retention_in_days"></a> [retention\_in\_days](#input\_retention\_in\_days) | Number of days you want to retain log events in the specified log group. | `number` | `1` | no |
99+
| <a name="input_sampled_requests_enabled"></a> [sampled\_requests\_enabled](#input\_sampled\_requests\_enabled) | Whether to enable simple requests | `bool` | `false` | no |
95100
| <a name="input_scalable_dimension"></a> [scalable\_dimension](#input\_scalable\_dimension) | The scalable dimension of the scalable target. | `string` | `"ecs:service:DesiredCount"` | no |
96101
| <a name="input_service_namespace"></a> [service\_namespace](#input\_service\_namespace) | The AWS service namespace of the scalable target. | `string` | `"ecs"` | no |
97102
| <a name="input_supporting_resources_name"></a> [supporting\_resources\_name](#input\_supporting\_resources\_name) | Name of the supporting resources stack | `string` | `"terraform-aws-ecs-service"` | no |

examples/complete/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,18 @@ module "ecs_service_alb" {
6464
enable_autoscaling = var.enable_autoscaling
6565
scalable_dimension = var.scalable_dimension
6666
service_namespace = var.service_namespace
67+
metric_aggregation_type = "Average"
68+
69+
# WAF association
70+
associate_with_waf = true
71+
web_acl_arn = module.waf_acl.arn
6772

6873
# Load balancer sg
6974
lb_ingress_rules = var.alb_ingress_rules
70-
depends_on = [module.access_logs_bucket]
75+
depends_on = [
76+
module.access_logs_bucket,
77+
module.waf_acl
78+
]
7179
}
7280

7381
module "ecs_service_nlb" {

examples/complete/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ variable "name" {
44
default = "complete-ecs-example"
55
}
66

7+
variable "cloudwatch_metrics_enabled" {
8+
type = bool
9+
description = "Whether to enable cloudwatch metrics"
10+
default = false
11+
}
12+
13+
variable "sampled_requests_enabled" {
14+
type = bool
15+
description = "Whether to enable simple requests"
16+
default = false
17+
}
18+
19+
variable "custom_header_name" {
20+
type = string
21+
description = "The name of the custom header to insert"
22+
default = "X-My-Company-Tracking-ID"
23+
}
24+
25+
variable "custom_header_value" {
26+
type = string
27+
description = "The value of the custom header to insert"
28+
default = "1234567890"
29+
}
30+
731
variable "supporting_resources_name" {
832
type = string
933
description = "Name of the supporting resources stack"

examples/complete/waf.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
module "waf_acl" {
2+
source = "boldlink/waf/aws"
3+
version = "1.0.3"
4+
name = var.name
5+
description = "Waf acl rules for ecs service"
6+
tags = local.tags
7+
8+
custom_response_bodies = [
9+
{
10+
key = "custom_response_body_1",
11+
content = "You are not authorized to access this resource.",
12+
content_type = "TEXT_PLAIN"
13+
}
14+
]
15+
16+
default_action = "allow"
17+
18+
rules = [
19+
{
20+
name = "${var.name}-allow-rule"
21+
priority = 1
22+
23+
action = {
24+
allow = {
25+
custom_request_handling = {
26+
insert_header = {
27+
name = var.custom_header_name
28+
value = var.custom_header_value
29+
}
30+
}
31+
}
32+
}
33+
34+
statement = {
35+
geo_match_statement = {
36+
country_codes = ["GB"]
37+
}
38+
}
39+
40+
visibility_config = {
41+
cloudwatch_metrics_enabled = var.cloudwatch_metrics_enabled
42+
metric_name = "${var.name}-allow-metric"
43+
sampled_requests_enabled = var.sampled_requests_enabled
44+
}
45+
},
46+
{
47+
name = "${var.name}-block-rule"
48+
priority = 4
49+
rule_label = ["ExampleLabel"]
50+
action = {
51+
block = {
52+
custom_response = {
53+
custom_response_body_key = "custom_response_body_1"
54+
response_code = 412
55+
response_headers = [
56+
{
57+
name = "X-Custom-Header-1"
58+
value = "You are not authorized to access this resource."
59+
},
60+
]
61+
}
62+
}
63+
}
64+
statement = {
65+
geo_match_statement = {
66+
country_codes = ["US"]
67+
}
68+
}
69+
visibility_config = {
70+
cloudwatch_metrics_enabled = var.cloudwatch_metrics_enabled
71+
metric_name = "${var.name}-block-metric"
72+
sampled_requests_enabled = var.sampled_requests_enabled
73+
}
74+
},
75+
{
76+
name = "${var.name}-captcha"
77+
priority = 2
78+
79+
action = {
80+
captcha = {}
81+
}
82+
83+
statement = {
84+
geo_match_statement = {
85+
country_codes = ["NL"]
86+
}
87+
}
88+
89+
visibility_config = {
90+
cloudwatch_metrics_enabled = false
91+
metric_name = "${var.name}-captcha-metric"
92+
sampled_requests_enabled = false
93+
}
94+
}
95+
]
96+
}

examples/fargate/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
| Name | Version |
2727
|------|---------|
28-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.24.0 |
28+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
2929

3030
## Modules
3131

examples/minimum/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
| Name | Version |
2727
|------|---------|
28-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.24.0 |
28+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
2929

3030
## Modules
3131

tests/supportingResources/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This stack builds:
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.24.0 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
3535

3636
## Modules
3737

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ variable "policy_type" {
337337
}
338338

339339
variable "adjustment_type" {
340-
description = "Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity."
340+
description = "(Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity."
341341
type = string
342342
default = "ChangeInCapacity"
343343
}

0 commit comments

Comments
 (0)