Skip to content

Commit fb87d99

Browse files
feat: update code and tflint issue (#28)
* feat: update code and tflint issue * feat: update code and tflint issue * feat: update code and tflint issue --------- Co-authored-by: anmolnagpal <[email protected]>
1 parent d81bbe1 commit fb87d99

File tree

8 files changed

+79
-64
lines changed

8 files changed

+79
-64
lines changed

_example/individual/example.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ module "cloudtrail" {
99

1010
name = "trails"
1111
environment = "test"
12-
label_order = ["environment", "application", "name"]
12+
label_order = ["environment", "name"]
1313

1414
enabled = true
15-
secure_s3_enabled = false
1615
iam_role_name = "CloudTrail-CloudWatch-Delivery-Role"
1716
iam_role_policy_name = "CloudTrail-CloudWatch-Delivery-Policy"
1817
account_type = "individual"

_example/individual/outputs.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ output "cloudtrail_arn" {
33
description = "The Amazon Resource Name of the trail"
44
}
55

6-
output "kms_arn" {
7-
value = module.cloudtrail[*].kms_arn
8-
description = "The Amazon Resource Name of the kms"
9-
}
6+
#output "kms_arn" {
7+
# value = module.cloudtrail[*].kms_arn
8+
# description = "The Amazon Resource Name of the kms"
9+
#}
1010

1111
output "tags" {
1212
value = module.cloudtrail.tags

_example/master/example.tf

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module "cloudtrail" {
1818
USER_IGNORE_LIST = jsonencode(["^awslambda_*", "^aws-batch$", "^bamboo*", "^i-*", "^[0-9]*$", "^ecs-service-scheduler$", "^AutoScaling$", "^AWSCloudFormation$", "^CloudTrailBot$", "^SLRManagement$"])
1919
SOURCE_LIST = jsonencode(["aws-sdk-go"])
2020
s3_bucket_name = "test-cloudtrail-bucket"
21-
secure_s3_enabled = false
2221
s3_log_bucket_name = "test-clouddtrail-logs"
2322
sse_algorithm = "aws:kms"
2423
additional_member_root_arn = ["arn:aws:iam::xxxxxxxxxxxx:root"]

_example/master/outputs.tf

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ output "cloudtrail_arn" {
33
description = "The Amazon Resource Name of the trail"
44
}
55

6-
output "kms_arn" {
7-
value = module.cloudtrail[*].kms_arn
8-
description = "The Amazon Resource Name of the kms"
9-
}
10-
116
output "tags" {
127
value = module.cloudtrail.tags
138
description = "A mapping of tags to assign to the Cloudtrail."

_example/member/example.tf

+47
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ provider "aws" {
22
region = "eu-west-1"
33
}
44

5+
data "aws_caller_identity" "current" {}
56

67
module "cloudtrail" {
78
source = "./../../"
@@ -20,4 +21,50 @@ module "cloudtrail" {
2021

2122
s3_bucket_name = "logs-bucket-cd"
2223
s3_log_bucket_name = "logs-bucket-cd-logs"
24+
s3_policy = data.aws_iam_policy_document.default.json
25+
}
26+
27+
data "aws_iam_policy_document" "default" {
28+
statement {
29+
sid = "AWSCloudTrailAclCheck"
30+
31+
principals {
32+
type = "Service"
33+
identifiers = ["cloudtrail.amazonaws.com"]
34+
}
35+
36+
actions = [
37+
"s3:GetBucketAcl",
38+
]
39+
40+
resources = ["arn:aws:s3:::logs-bucket-clouddrove"]
41+
}
42+
43+
statement {
44+
sid = "AWSCloudTrailWrite"
45+
46+
principals {
47+
type = "Service"
48+
identifiers = ["cloudtrail.amazonaws.com"]
49+
}
50+
51+
actions = [
52+
"s3:PutObject",
53+
]
54+
55+
resources = compact(
56+
concat(
57+
[format("arn:aws:s3:::logs-bucket-clouddrove/AWSLogs/%s/*", data.aws_caller_identity.current.account_id)]
58+
)
59+
)
60+
61+
condition {
62+
test = "StringEquals"
63+
variable = "s3:x-amz-acl"
64+
65+
values = [
66+
"bucket-owner-full-control",
67+
]
68+
}
69+
}
2370
}

main.tf

+27-35
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,31 @@
55
data "aws_caller_identity" "current" {}
66
data "aws_region" "current" {}
77

8-
#Module : Label
9-
#Description : This terraform module is designed to generate consistent label names and
10-
# tags for resources. You can use terraform-labels to implement a strict
11-
# naming convention
8+
##-----------------------------------------------------------------------------
9+
## Labels module callled that will be used for naming and tags.
10+
##-----------------------------------------------------------------------------
1211
module "labels" {
13-
source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.15.0"
14-
12+
source = "clouddrove/labels/aws"
13+
version = "1.3.0"
1514
name = var.name
1615
environment = var.environment
17-
label_order = var.label_order
1816
managedby = var.managedby
19-
enabled = var.enabled
17+
label_order = var.label_order
2018
}
2119

22-
2320
# Module : S3 BUCKET
2421
# Description : Terraform module to create default S3 bucket with logging and encryption
2522
# type specific features.
2623

2724
module "s3_log_bucket" {
2825
source = "git::https://github.com/clouddrove/terraform-aws-s3.git?ref=tags/2.0.0"
2926

30-
name = var.s3_log_bucket_name
31-
environment = var.environment
32-
label_order = ["name"]
33-
managedby = var.managedby
34-
create_bucket = local.is_cloudtrail_enabled
35-
bucket_enabled = var.enabled
36-
versioning = true
37-
acl = "private"
27+
name = var.s3_log_bucket_name
28+
environment = var.environment
29+
label_order = ["name"]
30+
managedby = var.managedby
31+
versioning = true
32+
acl = "private"
3833
}
3934

4035
module "s3_bucket" {
@@ -51,28 +46,24 @@ module "s3_bucket" {
5146
force_destroy = true
5247
target_bucket = module.s3_log_bucket.id
5348
target_prefix = "logs"
54-
mfa_delete = var.mfa_delete
5549
}
5650

5751
module "secure_s3_bucket" {
5852
source = "git::https://github.com/clouddrove/terraform-aws-s3.git?ref=tags/2.0.0"
5953

60-
name = var.s3_bucket_name
61-
environment = var.environment
62-
label_order = ["name"]
63-
managedby = var.managedby
64-
create_bucket = local.is_cloudtrail_enabled && var.secure_s3_enabled
65-
bucket_logging_encryption_enabled = var.enabled && var.secure_s3_enabled
66-
versioning = true
67-
acl = "private"
68-
bucket_policy = true
69-
aws_iam_policy_document = var.s3_policy
70-
force_destroy = true
71-
sse_algorithm = var.sse_algorithm
72-
kms_master_key_id = var.key_arn == "" ? module.kms_key.key_arn : var.key_arn
73-
target_bucket = module.s3_log_bucket.id
74-
target_prefix = "logs"
75-
mfa_delete = var.mfa_delete
54+
name = var.s3_bucket_name
55+
environment = var.environment
56+
label_order = ["name"]
57+
managedby = var.managedby
58+
versioning = true
59+
acl = "private"
60+
bucket_policy = true
61+
aws_iam_policy_document = var.s3_policy
62+
force_destroy = true
63+
sse_algorithm = var.sse_algorithm
64+
kms_master_key_id = var.key_arn == "" ? module.kms_key.key_arn : var.key_arn
65+
target_bucket = module.s3_log_bucket.id
66+
target_prefix = "logs"
7667
}
7768

7869
#Module : AWS_CLOUDWATCH_LOG_GROUP
@@ -340,7 +331,8 @@ locals {
340331
#Description : Terraform module to provision an AWS CloudTrail with encrypted S3 bucket.
341332
# This bucket is used to store CloudTrail logs.
342333
module "cloudtrail" {
343-
source = "git::https://github.com/clouddrove/terraform-aws-cloudtrail.git?ref=tags/1.4.0"
334+
source = "clouddrove/cloudtrail/aws"
335+
version = "1.4.0"
344336

345337
name = var.name
346338
environment = var.environment

outputs.tf

-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ output "s3_arn" {
2929
description = "The ARN of S3 bucket."
3030
}
3131

32-
output "kms_arn" {
33-
value = module.kms_key.key_arn
34-
description = "The ARN of KMS key."
35-
}
36-
3732
output "tags" {
3833
value = module.labels.tags
3934
description = "A mapping of tags to assign to the resource."

variables.tf

-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ variable "lambda_enabled" {
3030
description = "Whether to create lambda for cloudtrail logs."
3131
}
3232

33-
variable "secure_s3_enabled" {
34-
type = bool
35-
default = true
36-
description = "Whether to create secure s3 for cloudtrail logs."
37-
}
38-
39-
variable "mfa_delete" {
40-
type = bool
41-
default = false
42-
description = "Whether to enable mfa_delete or not."
43-
}
44-
4533
variable "slack_webhook" {
4634
type = string
4735
default = ""

0 commit comments

Comments
 (0)