Skip to content

Commit fde31e5

Browse files
authored
Merge branch 'main' into mw/azure-layered-terraform-samples
2 parents ec500f4 + 0188ee8 commit fde31e5

48 files changed

Lines changed: 607 additions & 952 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/trivy.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Trivy Security Scan
2+
on:
3+
pull_request:
4+
paths:
5+
- 'terraform/**'
6+
- '.github/workflows/trivy.yaml'
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- 'terraform/**'
12+
- '.github/workflows/trivy.yaml'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
trivy-aws:
20+
name: Trivy IaC Scan (AWS)
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
security-events: write
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Run Trivy scanner (table output)
30+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
31+
with:
32+
scan-type: 'fs'
33+
scan-ref: 'terraform/aws/modules/'
34+
scanners: 'vuln,secret,misconfig'
35+
ignore-unfixed: false
36+
exit-code: '0'
37+
format: 'table'
38+
severity: 'CRITICAL,HIGH'
39+
40+
- name: Run Trivy scanner (SARIF output)
41+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
42+
with:
43+
scan-type: 'fs'
44+
scan-ref: 'terraform/aws/modules/'
45+
scanners: 'vuln,secret,misconfig'
46+
ignore-unfixed: false
47+
exit-code: '0'
48+
format: 'sarif'
49+
output: 'trivy-aws-results.sarif'
50+
severity: 'CRITICAL,HIGH'
51+
52+
- name: Upload AWS scan results to GitHub Security tab
53+
uses: github/codeql-action/upload-sarif@v3
54+
if: always()
55+
with:
56+
sarif_file: 'trivy-aws-results.sarif'
57+
category: 'trivy-iac-aws'
58+
59+
trivy-azure:
60+
name: Trivy IaC Scan (Azure)
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
security-events: write
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Run Trivy scanner (table output)
70+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
71+
with:
72+
scan-type: 'fs'
73+
scan-ref: 'terraform/azure/modules/'
74+
scanners: 'vuln,secret,misconfig'
75+
ignore-unfixed: false
76+
exit-code: '0'
77+
format: 'table'
78+
severity: 'CRITICAL,HIGH'
79+
80+
- name: Run Trivy scanner (SARIF output)
81+
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
82+
with:
83+
scan-type: 'fs'
84+
scan-ref: 'terraform/azure/modules/'
85+
scanners: 'vuln,secret,misconfig'
86+
ignore-unfixed: false
87+
exit-code: '0'
88+
format: 'sarif'
89+
output: 'trivy-azure-results.sarif'
90+
severity: 'CRITICAL,HIGH'
91+
92+
- name: Upload Azure scan results to GitHub Security tab
93+
uses: github/codeql-action/upload-sarif@v3
94+
if: always()
95+
with:
96+
sarif_file: 'trivy-azure-results.sarif'
97+
category: 'trivy-iac-azure'

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ terraform.rc
3838
__MACOSX
3939

4040
# Configs to Ignore
41-
provider.tf
4241
inputs.tfvars

CODEOWNERS

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# This file details who the code owners are. Code owners are automatically requested for review when a PR is created.
2-
# For details on the format, and condfiguration of this file see: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
3-
4-
2+
# For details on the format, and configuration of this file see: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
3+
* @cmansky @EmmanuelNwa247 @jolson490 @mww59 @rin-skylight @szamfir-skylight
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# #https://registry.terraform.io/providers/grafana/grafana/1.30.0
2+
terraform {
3+
required_providers {
4+
grafana = {
5+
source = "grafana/grafana"
6+
version = ">=4.19.0, < 5.0.0"
7+
}
8+
}
9+
}
10+
11+
# provider "grafana" {
12+
# alias = "cloud"
13+
# url = var.grafana_workspace_url
14+
# auth = var.amg_api_token #grafana_service_account_token.admin-sa-token.key #
15+
# }

terraform/aws/modules/2-nbs7/eks-nbs/irsa.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module "otel_collector_irsa_role" {
5050
}
5151

5252
policies = {
53-
policy = aws_iam_policy.otel_collector_irsa_policy[0].arn
53+
policy = try(aws_iam_policy.otel_collector_irsa_policy[0].arn, null)
5454
}
5555
}
5656

@@ -96,7 +96,7 @@ module "datacompare_irsa_role" {
9696
}
9797

9898
policies = {
99-
policy = aws_iam_policy.datacompare_irsa_policy[0].arn
99+
policy = try(aws_iam_policy.datacompare_irsa_policy[0].arn, null)
100100
}
101101
}
102102

terraform/aws/modules/2-nbs7/eks-nbs/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ output "readonly_role_arns" {
4141

4242
output "otel_collector_role_arn" {
4343
description = "OTEL Collector IRSA role ARN — pass to helm install via --set serviceAccount.annotations"
44-
value = var.create_otel_collector_irsa ? module.otel_collector_irsa_role.iam_role_arn : null
44+
value = var.create_otel_collector_irsa ? module.otel_collector_irsa_role.arn : null
4545
}

terraform/aws/modules/2-nbs7/msk/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Below are the input parameter variables for the MSK:
1616
| modern-cidr | string | | VPC CIDR to be used with cluster SG |
1717
| msk_ebs_volume_size | number | | EBS volume size for the MSK broker nodes in GB |
1818
| msk_security_groups | list(string) | | A list of security groups to use for the MSK cluster |
19-
| msk_subnet_ids | list(string) | | A list of subnets to use for the MSK cluster |
19+
| msk_subnet_ids | list(string) | | A list of subnets to use for the MSK cluster. Must contain two subnets for 'development' otherwise three subnets for 'production', in order to match the number of brokers. |
2020
| resource_prefix | string | | Prefix for resource names |
2121
| vpc_id | string | | VPC Id to be used with cluster |
2222
| vpn-cidr | string | | VPN VPC CIDR to be used with cluster SG |
@@ -32,5 +32,3 @@ Below are the referenceable outputs from this module.
3232
## Module Dependencies
3333

3434
Dependencies are external modules that this module references. A module is considered external if it isn't within the same repository.
35-
36-

terraform/aws/modules/2-nbs7/msk/main.tf

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
locals {
22
module_name = "msk"
3-
module_serial_number = "2023071301" # update with each commit? Date plus two digit increment
3+
module_serial_number = "2026-04-30_01" # Update with each commit? Date plus two digit increment.
44
instance_type = var.environment == "development" ? "kafka.t3.small" : "kafka.m5.large"
5-
instance_count = var.environment == "development" ? 2 : 3
5+
number_of_brokers = var.environment == "development" ? 2 : 3
66
}
77

88
# Create an IAM role for MSK
@@ -126,7 +126,7 @@ resource "aws_msk_cluster" "this" {
126126
count = var.create_msk ? 1 : 0
127127
cluster_name = "${var.resource_prefix}-${var.environment}-msk-cluster"
128128
kafka_version = var.kafka_version
129-
number_of_broker_nodes = local.instance_count
129+
number_of_broker_nodes = local.number_of_brokers
130130
#iam_instance_profile = aws_iam_role.msk.arn
131131

132132
configuration_info {
@@ -173,23 +173,27 @@ resource "aws_msk_cluster" "this" {
173173
}
174174
}
175175

176-
177176
tags = {
178177
Environment = var.environment
179178
ModuleVersion = "${local.module_name}-${local.module_serial_number}"
180179
}
181180
}
182181

183-
resource "aws_msk_configuration" "msk_configuration_environment" {
184-
count = var.create_msk ? 1 : 0
185-
kafka_versions = ["2.8.1"]
186-
name = "${var.resource_prefix}-${var.environment}-msk-cluster-config"
187-
182+
locals {
183+
# Reference info: https://docs.confluent.io/platform/current/installation/configuration/index.html
184+
#
185+
# For production, as noted on https://docs.aws.amazon.com/msk/latest/developerguide/bestpractices.html it's a best practice to set RF (Replication Factor) to 3, and set MinISR (min.insync.replicas) to at most RF - 1.
186+
# For non-production, if minimizing resource usage is more of a priority to you than simulating production behavior, then set MinISR=1 and RF=2.
187+
# Note that if you are using AWS MSK and if you set MinISR >= RF then you'll receive a notification in AWS User Notifications advising you to change your configuration so that MinISR is at most RF - 1.
188+
#
189+
# More considerations for production environments:
190+
# * https://repost.aws/knowledge-center/msk-avoid-disruption-during-patching
191+
# * https://docs.aws.amazon.com/securityhub/latest/userguide/msk-controls.html
188192
server_properties = <<PROPERTIES
189193
auto.create.topics.enable = true
190194
delete.topic.enable = true
191-
default.replication.factor=2
192-
min.insync.replicas=2
195+
default.replication.factor=${local.number_of_brokers}
196+
min.insync.replicas=1
193197
num.io.threads=8
194198
num.network.threads=5
195199
num.partitions=1
@@ -200,12 +204,16 @@ socket.request.max.bytes=104857600
200204
socket.send.buffer.bytes=102400
201205
unclean.leader.election.enable=true
202206
zookeeper.session.timeout.ms=18000
203-
offsets.topic.replication.factor=2
204-
transaction.state.log.replication.factor=2
207+
offsets.topic.replication.factor=${local.number_of_brokers}
208+
transaction.state.log.replication.factor=${local.number_of_brokers}
205209
PROPERTIES
206210
}
207211

212+
# Reference info: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/msk_configuration
213+
resource "aws_msk_configuration" "msk_configuration_environment" {
214+
count = var.create_msk ? 1 : 0
215+
kafka_versions = ["2.8.1"]
216+
name = "${var.resource_prefix}-${var.environment}-msk-cluster-config"
208217

209-
210-
211-
218+
server_properties = local.server_properties
219+
}

terraform/azure/modules/0_landing_zone/README.md

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)