Skip to content

Commit 0d6e2d5

Browse files
author
iru
authored
refact: enable optional cloudtrail (#43)
1 parent ce44f75 commit 0d6e2d5

File tree

14 files changed

+81
-36
lines changed

14 files changed

+81
-36
lines changed

examples/organizational/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Notice that:
116116
| <a name="input_benchmark_regions"></a> [benchmark\_regions](#input\_benchmark\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default. | `list(string)` | `[]` | no |
117117
| <a name="input_cloudtrail_is_multi_region_trail"></a> [cloudtrail\_is\_multi\_region\_trail](#input\_cloudtrail\_is\_multi\_region\_trail) | true/false whether cloudtrail will ingest multiregional events. testing/economization purpose. | `bool` | `true` | no |
118118
| <a name="input_cloudtrail_kms_enable"></a> [cloudtrail\_kms\_enable](#input\_cloudtrail\_kms\_enable) | true/false whether cloudtrail delivered events to S3 should persist encrypted | `bool` | `true` | no |
119+
| <a name="input_cloudtrail_s3_arn"></a> [cloudtrail\_s3\_arn](#input\_cloudtrail\_s3\_arn) | ARN of a pre-existing cloudtrail\_sns s3 bucket. If it does not exist, it will be inferred from create cloudtrail | `string` | `"create"` | no |
120+
| <a name="input_cloudtrail_sns_arn"></a> [cloudtrail\_sns\_arn](#input\_cloudtrail\_sns\_arn) | ARN of a pre-existing cloudtrail\_sns. If it does not exist, it will be inferred from created cloudtrail | `string` | `"create"` | no |
119121
| <a name="input_connector_ecs_task_role_name"></a> [connector\_ecs\_task\_role\_name](#input\_connector\_ecs\_task\_role\_name) | Name for the ecs task role. This is only required to resolve cyclic dependency with organizational approach | `string` | `"organizational-ECSTaskRole"` | no |
120122
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
121123
| <a name="input_organizational_member_default_admin_role"></a> [organizational\_member\_default\_admin\_role](#input\_organizational\_member\_default\_admin\_role) | Default role created by AWS for managed-account users to be able to admin member accounts.<br/>https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_access.html | `string` | `"OrganizationAccountAccessRole"` | no |

examples/organizational/cloudtrail.tf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
locals {
2+
cloudtrail_deploy = var.cloudtrail_sns_arn == "create"
3+
cloudtrail_sns_arn = var.cloudtrail_sns_arn == "create" ? module.cloudtrail[0].sns_topic_arn : var.cloudtrail_sns_arn
4+
cloudtrail_s3_arn = var.cloudtrail_sns_arn == "create" ? module.cloudtrail[0].s3_bucket_arn : var.cloudtrail_s3_arn
5+
}
6+
7+
8+
module "cloudtrail" {
9+
count = local.cloudtrail_deploy ? 1 : 0
10+
source = "../../modules/infrastructure/cloudtrail"
11+
name = var.name
12+
13+
is_organizational = true
14+
organizational_config = {
15+
sysdig_secure_for_cloud_member_account_id = var.sysdig_secure_for_cloud_member_account_id
16+
organizational_role_per_account = var.organizational_member_default_admin_role
17+
}
18+
is_multi_region_trail = var.cloudtrail_is_multi_region_trail
19+
cloudtrail_kms_enable = var.cloudtrail_kms_enable
20+
21+
tags = var.tags
22+
}

examples/organizational/credentials.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ module "resource_group_secure_for_cloud_member" {
77
tags = var.tags
88
}
99

10-
1110
module "secure_for_cloud_role" {
1211
source = "../../modules/infrastructure/permissions/ecs-org-role"
1312
providers = {
1413
aws.member = aws.member
1514
}
1615
name = var.name
1716

18-
cloudtrail_s3_arn = module.cloudtrail.s3_bucket_arn
17+
cloudtrail_s3_arn = local.cloudtrail_s3_arn
1918
cloudconnector_ecs_task_role_name = aws_iam_role.connector_ecs_task.name
2019
organizational_role_per_account = var.organizational_member_default_admin_role
2120

examples/organizational/main.tf

+4-19
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ module "resource_group" {
2525
tags = var.tags
2626
}
2727

28-
module "cloudtrail" {
29-
source = "../../modules/infrastructure/cloudtrail"
30-
name = var.name
31-
32-
is_organizational = true
33-
organizational_config = {
34-
sysdig_secure_for_cloud_member_account_id = var.sysdig_secure_for_cloud_member_account_id
35-
organizational_role_per_account = var.organizational_member_default_admin_role
36-
}
37-
is_multi_region_trail = var.cloudtrail_is_multi_region_trail
38-
cloudtrail_kms_enable = var.cloudtrail_kms_enable
39-
40-
tags = var.tags
41-
}
42-
4328

4429
#-------------------------------------
4530
# secure-for-cloud member account workload
@@ -84,14 +69,14 @@ module "cloud_connector" {
8469
connector_ecs_task_role_name = aws_iam_role.connector_ecs_task.name
8570
}
8671

87-
sns_topic_arn = module.cloudtrail.sns_topic_arn
72+
sns_topic_arn = local.cloudtrail_sns_arn
8873

8974
ecs_cluster = module.ecs_fargate_cluster.id
9075
vpc_id = module.ecs_fargate_cluster.vpc_id
9176
vpc_subnets = module.ecs_fargate_cluster.vpc_subnets
9277

9378
tags = var.tags
94-
depends_on = [module.cloudtrail, module.ecs_fargate_cluster, module.ssm]
79+
depends_on = [local.cloudtrail_sns_arn, module.ecs_fargate_cluster, module.ssm]
9580
}
9681

9782
#
@@ -129,14 +114,14 @@ module "cloud_scanning" {
129114
scanning_ecs_task_role_name = aws_iam_role.connector_ecs_task.name
130115
}
131116

132-
sns_topic_arn = module.cloudtrail.sns_topic_arn
117+
sns_topic_arn = local.cloudtrail_sns_arn
133118

134119
ecs_cluster = module.ecs_fargate_cluster.id
135120
vpc_id = module.ecs_fargate_cluster.vpc_id
136121
vpc_subnets = module.ecs_fargate_cluster.vpc_subnets
137122

138123
tags = var.tags
139-
depends_on = [module.cloudtrail, module.ecs_fargate_cluster, module.codebuild, module.ssm]
124+
depends_on = [local.cloudtrail_sns_arn, module.ecs_fargate_cluster, module.codebuild, module.ssm]
140125
}
141126

142127
#-------------------------------------

examples/organizational/variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ variable "organizational_member_default_admin_role" {
3434
# cloudtrail configuration
3535
#
3636

37+
variable "cloudtrail_sns_arn" {
38+
type = string
39+
default = "create"
40+
description = "ARN of a pre-existing cloudtrail_sns. If it does not exist, it will be inferred from created cloudtrail"
41+
}
42+
43+
variable "cloudtrail_s3_arn" {
44+
type = string
45+
default = "create"
46+
description = "ARN of a pre-existing cloudtrail_sns s3 bucket. If it does not exist, it will be inferred from create cloudtrail"
47+
}
48+
3749
variable "cloudtrail_is_multi_region_trail" {
3850
type = bool
3951
default = true

examples/single-account-k8s/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Notice that:
104104
| <a name="input_sysdig_secure_api_token"></a> [sysdig\_secure\_api\_token](#input\_sysdig\_secure\_api\_token) | Sysdig Secure API token | `string` | n/a | yes |
105105
| <a name="input_cloudtrail_is_multi_region_trail"></a> [cloudtrail\_is\_multi\_region\_trail](#input\_cloudtrail\_is\_multi\_region\_trail) | true/false whether cloudtrail will ingest multiregional events. testing/economization purpose. | `bool` | `true` | no |
106106
| <a name="input_cloudtrail_kms_enable"></a> [cloudtrail\_kms\_enable](#input\_cloudtrail\_kms\_enable) | true/false whether s3 should be encrypted. testing/economization purpose. | `bool` | `true` | no |
107+
| <a name="input_cloudtrail_sns_arn"></a> [cloudtrail\_sns\_arn](#input\_cloudtrail\_sns\_arn) | ARN of a pre-existing cloudtrail\_sns. If it does not exist, it will be inferred from created cloudtrail | `string` | `"create"` | no |
107108
| <a name="input_deploy_image_scanning"></a> [deploy\_image\_scanning](#input\_deploy\_image\_scanning) | true/false whether to deploy cloud\_scanning | `bool` | `true` | no |
108109
| <a name="input_deploy_threat_detection"></a> [deploy\_threat\_detection](#input\_deploy\_threat\_detection) | true/false whether to deploy cloud\_connector | `bool` | `true` | no |
109110
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |

examples/single-account-k8s/cloud-connector.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module "cloud_connector_sqs" {
66
source = "../../modules/infrastructure/sqs-sns-subscription"
77

88
name = "${var.name}-cloud_connector"
9-
sns_topic_arn = module.cloudtrail.sns_topic_arn
9+
sns_topic_arn = local.cloudtrail_sns_arn
1010
tags = var.tags
1111
}
1212

examples/single-account-k8s/cloud-scanning.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module "cloud_scanning_sqs" {
66
source = "../../modules/infrastructure/sqs-sns-subscription"
77

88
name = "${var.name}-cloud_scanning"
9-
sns_topic_arn = module.cloudtrail.sns_topic_arn
9+
sns_topic_arn = local.cloudtrail_sns_arn
1010
tags = var.tags
1111
}
1212

examples/single-account-k8s/cloudtrail.tf

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
locals {
2+
cloudtrail_deploy = var.cloudtrail_sns_arn == "create"
3+
cloudtrail_sns_arn = var.cloudtrail_sns_arn == "create" ? module.cloudtrail[0].sns_topic_arn : var.cloudtrail_sns_arn
4+
}
5+
16
module "cloudtrail" {
7+
count = local.cloudtrail_deploy ? 1 : 0
28
source = "../../modules/infrastructure/cloudtrail"
39
name = var.name
410

examples/single-account-k8s/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ variable "deploy_image_scanning" {
2525
# cloudtrail configuration
2626
#
2727

28+
variable "cloudtrail_sns_arn" {
29+
type = string
30+
default = "create"
31+
description = "ARN of a pre-existing cloudtrail_sns. If it does not exist, it will be inferred from created cloudtrail"
32+
}
33+
2834
variable "cloudtrail_is_multi_region_trail" {
2935
type = bool
3036
default = true

examples/single-account/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ No resources.
8282
| <a name="input_benchmark_regions"></a> [benchmark\_regions](#input\_benchmark\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all aws regions by default. | `list(string)` | `[]` | no |
8383
| <a name="input_cloudtrail_is_multi_region_trail"></a> [cloudtrail\_is\_multi\_region\_trail](#input\_cloudtrail\_is\_multi\_region\_trail) | true/false whether cloudtrail will ingest multiregional events | `bool` | `true` | no |
8484
| <a name="input_cloudtrail_kms_enable"></a> [cloudtrail\_kms\_enable](#input\_cloudtrail\_kms\_enable) | true/false whether cloudtrail delivered events to S3 should persist encrypted | `bool` | `true` | no |
85+
| <a name="input_cloudtrail_sns_arn"></a> [cloudtrail\_sns\_arn](#input\_cloudtrail\_sns\_arn) | ARN of a pre-existing cloudtrail\_sns. If it does not exist, it will be inferred from created cloudtrail | `string` | `"create"` | no |
8586
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
8687
| <a name="input_sysdig_secure_endpoint"></a> [sysdig\_secure\_endpoint](#input\_sysdig\_secure\_endpoint) | Sysdig Secure API endpoint | `string` | `"https://secure.sysdig.com"` | no |
8788
| <a name="input_tags"></a> [tags](#input\_tags) | sysdig secure-for-cloud tags | `map(string)` | <pre>{<br> "product": "sysdig-secure-for-cloud"<br>}</pre> | no |

examples/single-account/cloudtrail.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
locals {
2+
cloudtrail_deploy = var.cloudtrail_sns_arn == "create"
3+
cloudtrail_sns_arn = var.cloudtrail_sns_arn == "create" ? module.cloudtrail[0].sns_topic_arn : var.cloudtrail_sns_arn
4+
}
5+
6+
module "cloudtrail" {
7+
count = local.cloudtrail_deploy ? 1 : 0
8+
source = "../../modules/infrastructure/cloudtrail"
9+
name = var.name
10+
is_organizational = false
11+
is_multi_region_trail = var.cloudtrail_is_multi_region_trail
12+
cloudtrail_kms_enable = var.cloudtrail_kms_enable
13+
14+
tags = var.tags
15+
}

examples/single-account/main.tf

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ module "resource_group" {
88
tags = var.tags
99
}
1010

11-
module "cloudtrail" {
12-
source = "../../modules/infrastructure/cloudtrail"
13-
name = var.name
14-
is_organizational = false
15-
is_multi_region_trail = var.cloudtrail_is_multi_region_trail
16-
cloudtrail_kms_enable = var.cloudtrail_kms_enable
17-
18-
tags = var.tags
19-
}
2011

2112
module "ecs_fargate_cluster" {
2213
source = "../../modules/infrastructure/ecs-fargate-cluster"
@@ -44,14 +35,14 @@ module "cloud_connector" {
4435
secure_api_token_secret_name = module.ssm.secure_api_token_secret_name
4536
is_organizational = false
4637

47-
sns_topic_arn = module.cloudtrail.sns_topic_arn
38+
sns_topic_arn = local.cloudtrail_sns_arn
4839

4940
ecs_cluster = module.ecs_fargate_cluster.id
5041
vpc_id = module.ecs_fargate_cluster.vpc_id
5142
vpc_subnets = module.ecs_fargate_cluster.vpc_subnets
5243

5344
tags = var.tags
54-
depends_on = [module.cloudtrail, module.ecs_fargate_cluster, module.ssm]
45+
depends_on = [local.cloudtrail_sns_arn, module.ecs_fargate_cluster, module.ssm]
5546
}
5647

5748

@@ -81,15 +72,15 @@ module "cloud_scanning" {
8172
build_project_arn = module.codebuild.project_arn
8273
build_project_name = module.codebuild.project_name
8374

84-
sns_topic_arn = module.cloudtrail.sns_topic_arn
75+
sns_topic_arn = local.cloudtrail_sns_arn
8576

8677
ecs_cluster = module.ecs_fargate_cluster.id
8778
vpc_id = module.ecs_fargate_cluster.vpc_id
8879
vpc_subnets = module.ecs_fargate_cluster.vpc_subnets
8980

9081
tags = var.tags
9182
# note. this is required to avoid race conditions
92-
depends_on = [module.cloudtrail, module.ecs_fargate_cluster, module.codebuild, module.ssm]
83+
depends_on = [local.cloudtrail_sns_arn, module.ecs_fargate_cluster, module.codebuild, module.ssm]
9384
}
9485

9586
#-------------------------------------

examples/single-account/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ variable "sysdig_secure_api_token" {
1212
#
1313
# cloudtrail configuration
1414
#
15+
variable "cloudtrail_sns_arn" {
16+
type = string
17+
default = "create"
18+
description = "ARN of a pre-existing cloudtrail_sns. If it does not exist, it will be inferred from created cloudtrail"
19+
}
1520

1621
variable "cloudtrail_is_multi_region_trail" {
1722
type = bool

0 commit comments

Comments
 (0)