Skip to content

Commit 9945837

Browse files
Added Test example to tf modules
1 parent b7722c6 commit 9945837

35 files changed

+428
-13
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
18+
# Terraform files
19+
*.terraform
20+
*.tfstate
21+
*.tfstate.backup
22+
*.terraform.lock.hcl
23+
.idea

aws/cloudtrail/cloudtrail.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ resource "random_string" "aws_random" {
1212
upper = false
1313
}
1414

15+
# Default s3 bucket acl is private, if you want to update uncomment the following block
16+
# For more details refer https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl
1517
resource "aws_s3_bucket" "s3_bucket" {
1618
for_each = toset(var.source_details.bucket_details.create_bucket ? ["s3_bucket"] : [])
1719

1820
bucket = local.bucket_name
1921
force_destroy = var.source_details.bucket_details.force_destroy_bucket
22+
}
2023

24+
resource "aws_s3_bucket_policy" "s3_bucket" {
25+
bucket = aws_s3_bucket.s3_bucket["s3_bucket"].id
2126
policy = templatefile("${path.module}/templates/cloudtrail_bucket_policy.tmpl", {
22-
BUCKET_NAME = local.bucket_name
27+
BUCKET_NAME = aws_s3_bucket.s3_bucket["s3_bucket"].id
2328
})
2429
}
2530

@@ -47,6 +52,7 @@ resource "aws_s3_bucket_notification" "bucket_notification" {
4752
}
4853

4954
resource "aws_cloudtrail" "cloudtrail" {
55+
depends_on = [aws_s3_bucket_policy.s3_bucket]
5056
for_each = toset(local.create_trail ? ["cloudtrail"] : [])
5157

5258
name = local.cloudtrail_name
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
data "aws_region" "current" {}
2+
3+
data "aws_caller_identity" "current" {}
4+
5+
data "sumologic_caller_identity" "current" {}
6+
7+
output "aws_account_id" {
8+
value = data.aws_caller_identity.current.account_id
9+
}
10+
11+
output "aws_region_data" {
12+
value = data.aws_region.current
13+
}
14+
15+
output "sumologic_env" {
16+
value = data.sumologic_caller_identity.current
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
locals {
2+
# Wait time
3+
wait_for_seconds = 180
4+
5+
# AWS account details
6+
aws_account_id = data.aws_caller_identity.current.account_id
7+
aws_region = data.aws_region.current.name
8+
create_iam_role = true
9+
# common_bucket_name = "aws-observability-${random_string.aws_random.id}"
10+
11+
# Sumo AWS account ID
12+
sumo_account_id = "926226587429"
13+
# Sumo account Details
14+
sumologic_organization_id = "0000000000285A74"
15+
sumologic_existing_collector_id = 170655886
16+
sumologic_environment = "us1"
17+
18+
# CloudTrail Source updated Details
19+
create_collector = true
20+
create_trail = true
21+
create_sns_topic = true
22+
cloudtrail_source_details = {
23+
source_name = "CloudTrail Logs (Region)"
24+
source_category = "aws/observability/cloudtrail/logs"
25+
description = "This source is created using Sumo Logic terraform AWS Observability module to collect AWS cloudtrail logs."
26+
bucket_details = {
27+
create_bucket = true
28+
bucket_name = "aws-observability-random-${local.sumologic_existing_collector_id}"
29+
path_expression = "AWSLogs/${local.aws_account_id}/CloudTrail/${local.aws_region}/*"
30+
force_destroy_bucket = true
31+
}
32+
}
33+
cloudtrail_fields = { account = local.aws_account_id }
34+
cloudtrail_source_bucket_name = "akhil_${local.aws_region}_${local.sumologic_organization_id}"
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
module "cloudtrail_module" {
3+
source = "../../../cloudtrail"
4+
5+
create_collector = local.create_collector
6+
create_trail = local.create_trail
7+
sumologic_organization_id = local.sumologic_organization_id
8+
wait_for_seconds = 20
9+
10+
source_details = {
11+
source_name = local.cloudtrail_source_details.source_name
12+
source_category = local.cloudtrail_source_details.source_category
13+
description = local.cloudtrail_source_details.description
14+
collector_id = local.sumologic_existing_collector_id
15+
bucket_details = {
16+
create_bucket = true
17+
bucket_name = local.cloudtrail_source_details.bucket_details.bucket_name
18+
path_expression = local.cloudtrail_source_details.bucket_details.path_expression
19+
force_destroy_bucket = false
20+
}
21+
paused = false
22+
scan_interval = 60000
23+
sumo_account_id = local.sumo_account_id
24+
cutoff_relative_time = "-1d"
25+
fields = local.cloudtrail_fields
26+
iam_details = {
27+
create_iam_role = true
28+
iam_role_arn = null
29+
}
30+
sns_topic_details = {
31+
create_sns_topic = true
32+
sns_topic_arn = null
33+
}
34+
}
35+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 0.13.0"
3+
4+
required_providers {
5+
sumologic = {
6+
version = ">= 2.28.3, < 3.0.0"
7+
source = "SumoLogic/sumologic"
8+
}
9+
aws = {
10+
source = "hashicorp/aws"
11+
version = ">= 5.43.0"
12+
}
13+
}
14+
}

aws/cloudtrail/versions.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ terraform {
33

44
required_providers {
55
aws = {
6-
source = "hashicorp/aws"
7-
version = ">= 3.42.0"
6+
source = "hashicorp/aws"
7+
version = ">= 5.16.2, < 6.0.0"
88
}
99
sumologic = {
10-
version = ">= 2.9.0"
10+
version = ">= 2.28.3, < 3.0.0"
1111
source = "SumoLogic/sumologic"
1212
}
1313
time = {

0 commit comments

Comments
 (0)