Skip to content

Commit b0d41e2

Browse files
feat: Add rules for Promtail and Loki (#277)
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
1 parent 700f32c commit b0d41e2

File tree

16 files changed

+1427
-6
lines changed

16 files changed

+1427
-6
lines changed

.github/workflows/pre-commit.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
env:
1010
TERRAFORM_DOCS_VERSION: v0.16.0
11+
TFLINT_VERSION: v0.44.1
1112

1213
jobs:
1314
collectInputs:
@@ -21,7 +22,7 @@ jobs:
2122

2223
- name: Get root directories
2324
id: dirs
24-
uses: clowdhaus/terraform-composite-actions/directories@v1.8.2
25+
uses: clowdhaus/terraform-composite-actions/directories@v1.8.3
2526

2627
preCommitMinVersions:
2728
name: Min TF pre-commit
@@ -43,17 +44,19 @@ jobs:
4344
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
4445
# Run only validate pre-commit check on min version supported
4546
if: ${{ matrix.directory != '.' }}
46-
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.2
47+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
4748
with:
4849
terraform-version: ${{ steps.minMax.outputs.minVersion }}
50+
tflint-version: ${{ env.TFLINT_VERSION }}
4951
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
5052

5153
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
5254
# Run only validate pre-commit check on min version supported
5355
if: ${{ matrix.directory == '.' }}
54-
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.2
56+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
5557
with:
5658
terraform-version: ${{ steps.minMax.outputs.minVersion }}
59+
tflint-version: ${{ env.TFLINT_VERSION }}
5760
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
5861

5962
preCommitMaxVersion:
@@ -76,8 +79,9 @@ jobs:
7679
run: rm -rf modules/_templates
7780

7881
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
79-
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.2
82+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
8083
with:
8184
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
85+
tflint-version: ${{ env.TFLINT_VERSION }}
8286
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
8387
install-hcledit: true

README.md

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

modules/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ List of Security Groups implemented as Terraform modules
2525
* [ldap](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/ldap)
2626
* [ldaps](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/ldaps)
2727
* [logstash](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/logstash)
28+
* [loki](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/loki)
2829
* [memcached](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/memcached)
2930
* [minio](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/minio)
3031
* [mongodb](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/mongodb)
@@ -37,6 +38,7 @@ List of Security Groups implemented as Terraform modules
3738
* [oracle-db](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/oracle-db)
3839
* [postgresql](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/postgresql)
3940
* [prometheus](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/prometheus)
41+
* [promtail](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/promtail)
4042
* [puppet](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/puppet)
4143
* [rabbitmq](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/rabbitmq)
4244
* [rdp](https://github.com/terraform-aws-modules/terraform-aws-security-group/tree/master/modules/rdp)

modules/loki/README.md

Lines changed: 120 additions & 0 deletions
Large diffs are not rendered by default.

modules/loki/auto_values.tf

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This file was generated from values defined in rules.tf using update_groups.sh.
2+
###################################
3+
# DO NOT CHANGE THIS FILE MANUALLY
4+
###################################
5+
6+
variable "auto_ingress_rules" {
7+
description = "List of ingress rules to add automatically"
8+
type = list(string)
9+
default = ["loki-grafana", "loki-grafana-grpc"]
10+
}
11+
12+
variable "auto_ingress_with_self" {
13+
description = "List of maps defining ingress rules with self to add automatically"
14+
type = list(map(string))
15+
default = [{ "rule" = "all-all" }]
16+
}
17+
18+
variable "auto_egress_rules" {
19+
description = "List of egress rules to add automatically"
20+
type = list(string)
21+
default = ["all-all"]
22+
}
23+
24+
variable "auto_egress_with_self" {
25+
description = "List of maps defining egress rules with self to add automatically"
26+
type = list(map(string))
27+
default = []
28+
}
29+
30+
# Computed
31+
variable "auto_computed_ingress_rules" {
32+
description = "List of ingress rules to add automatically"
33+
type = list(string)
34+
default = []
35+
}
36+
37+
variable "auto_computed_ingress_with_self" {
38+
description = "List of maps defining computed ingress rules with self to add automatically"
39+
type = list(map(string))
40+
default = []
41+
}
42+
43+
variable "auto_computed_egress_rules" {
44+
description = "List of computed egress rules to add automatically"
45+
type = list(string)
46+
default = []
47+
}
48+
49+
variable "auto_computed_egress_with_self" {
50+
description = "List of maps defining computed egress rules with self to add automatically"
51+
type = list(map(string))
52+
default = []
53+
}
54+
55+
# Number of computed rules
56+
variable "auto_number_of_computed_ingress_rules" {
57+
description = "Number of computed ingress rules to create by name"
58+
type = number
59+
default = 0
60+
}
61+
62+
variable "auto_number_of_computed_ingress_with_self" {
63+
description = "Number of computed ingress rules to create where 'self' is defined"
64+
type = number
65+
default = 0
66+
}
67+
68+
variable "auto_number_of_computed_egress_rules" {
69+
description = "Number of computed egress rules to create by name"
70+
type = number
71+
default = 0
72+
}
73+
74+
variable "auto_number_of_computed_egress_with_self" {
75+
description = "Number of computed egress rules to create where 'self' is defined"
76+
type = number
77+
default = 0
78+
}

modules/loki/main.tf

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
module "sg" {
2+
source = "../../"
3+
4+
create = var.create
5+
name = var.name
6+
use_name_prefix = var.use_name_prefix
7+
description = var.description
8+
vpc_id = var.vpc_id
9+
revoke_rules_on_delete = var.revoke_rules_on_delete
10+
tags = var.tags
11+
12+
##########
13+
# Ingress
14+
##########
15+
# Rules by names - open for default CIDR
16+
ingress_rules = sort(compact(distinct(concat(var.auto_ingress_rules, var.ingress_rules, [""]))))
17+
18+
# Open for self
19+
ingress_with_self = concat(var.auto_ingress_with_self, var.ingress_with_self)
20+
21+
# Open to IPv4 cidr blocks
22+
ingress_with_cidr_blocks = var.ingress_with_cidr_blocks
23+
24+
# Open to IPv6 cidr blocks
25+
ingress_with_ipv6_cidr_blocks = var.ingress_with_ipv6_cidr_blocks
26+
27+
# Open for security group id
28+
ingress_with_source_security_group_id = var.ingress_with_source_security_group_id
29+
30+
# Default ingress CIDR blocks
31+
ingress_cidr_blocks = var.ingress_cidr_blocks
32+
ingress_ipv6_cidr_blocks = var.ingress_ipv6_cidr_blocks
33+
34+
# Default prefix list ids
35+
ingress_prefix_list_ids = var.ingress_prefix_list_ids
36+
37+
###################
38+
# Computed Ingress
39+
###################
40+
# Rules by names - open for default CIDR
41+
computed_ingress_rules = sort(compact(distinct(concat(var.auto_computed_ingress_rules, var.computed_ingress_rules, [""]))))
42+
43+
# Open for self
44+
computed_ingress_with_self = concat(var.auto_computed_ingress_with_self, var.computed_ingress_with_self)
45+
46+
# Open to IPv4 cidr blocks
47+
computed_ingress_with_cidr_blocks = var.computed_ingress_with_cidr_blocks
48+
49+
# Open to IPv6 cidr blocks
50+
computed_ingress_with_ipv6_cidr_blocks = var.computed_ingress_with_ipv6_cidr_blocks
51+
52+
# Open for security group id
53+
computed_ingress_with_source_security_group_id = var.computed_ingress_with_source_security_group_id
54+
55+
#############################
56+
# Number of computed ingress
57+
#############################
58+
number_of_computed_ingress_rules = var.auto_number_of_computed_ingress_rules + var.number_of_computed_ingress_rules
59+
number_of_computed_ingress_with_self = var.auto_number_of_computed_ingress_with_self + var.number_of_computed_ingress_with_self
60+
number_of_computed_ingress_with_cidr_blocks = var.number_of_computed_ingress_with_cidr_blocks
61+
number_of_computed_ingress_with_ipv6_cidr_blocks = var.number_of_computed_ingress_with_ipv6_cidr_blocks
62+
number_of_computed_ingress_with_source_security_group_id = var.number_of_computed_ingress_with_source_security_group_id
63+
64+
#########
65+
# Egress
66+
#########
67+
# Rules by names - open for default CIDR
68+
egress_rules = sort(compact(distinct(concat(var.auto_egress_rules, var.egress_rules, [""]))))
69+
70+
# Open for self
71+
egress_with_self = concat(var.auto_egress_with_self, var.egress_with_self)
72+
73+
# Open to IPv4 cidr blocks
74+
egress_with_cidr_blocks = var.egress_with_cidr_blocks
75+
76+
# Open to IPv6 cidr blocks
77+
egress_with_ipv6_cidr_blocks = var.egress_with_ipv6_cidr_blocks
78+
79+
# Open for security group id
80+
egress_with_source_security_group_id = var.egress_with_source_security_group_id
81+
82+
# Default egress CIDR blocks
83+
egress_cidr_blocks = var.egress_cidr_blocks
84+
egress_ipv6_cidr_blocks = var.egress_ipv6_cidr_blocks
85+
86+
# Default prefix list ids
87+
egress_prefix_list_ids = var.egress_prefix_list_ids
88+
89+
##################
90+
# Computed Egress
91+
##################
92+
# Rules by names - open for default CIDR
93+
computed_egress_rules = sort(compact(distinct(concat(var.auto_computed_egress_rules, var.computed_egress_rules, [""]))))
94+
95+
# Open for self
96+
computed_egress_with_self = concat(var.auto_computed_egress_with_self, var.computed_egress_with_self)
97+
98+
# Open to IPv4 cidr blocks
99+
computed_egress_with_cidr_blocks = var.computed_egress_with_cidr_blocks
100+
101+
# Open to IPv6 cidr blocks
102+
computed_egress_with_ipv6_cidr_blocks = var.computed_egress_with_ipv6_cidr_blocks
103+
104+
# Open for security group id
105+
computed_egress_with_source_security_group_id = var.computed_egress_with_source_security_group_id
106+
107+
#############################
108+
# Number of computed egress
109+
#############################
110+
number_of_computed_egress_rules = var.auto_number_of_computed_egress_rules + var.number_of_computed_egress_rules
111+
number_of_computed_egress_with_self = var.auto_number_of_computed_egress_with_self + var.number_of_computed_egress_with_self
112+
number_of_computed_egress_with_cidr_blocks = var.number_of_computed_egress_with_cidr_blocks
113+
number_of_computed_egress_with_ipv6_cidr_blocks = var.number_of_computed_egress_with_ipv6_cidr_blocks
114+
number_of_computed_egress_with_source_security_group_id = var.number_of_computed_egress_with_source_security_group_id
115+
}

modules/loki/outputs.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
output "security_group_arn" {
2+
description = "The ARN of the security group"
3+
value = module.sg.security_group_arn
4+
}
5+
6+
output "security_group_id" {
7+
description = "The ID of the security group"
8+
value = module.sg.security_group_id
9+
}
10+
11+
output "security_group_vpc_id" {
12+
description = "The VPC ID"
13+
value = module.sg.security_group_vpc_id
14+
}
15+
16+
output "security_group_owner_id" {
17+
description = "The owner ID"
18+
value = module.sg.security_group_owner_id
19+
}
20+
21+
output "security_group_name" {
22+
description = "The name of the security group"
23+
value = module.sg.security_group_name
24+
}
25+
26+
output "security_group_description" {
27+
description = "The description of the security group"
28+
value = module.sg.security_group_description
29+
}

0 commit comments

Comments
 (0)