Skip to content

Commit 5699472

Browse files
authored
Merge pull request #20 from aquasecurity/idan-SLK-100239-fix-race-and-add-base-cspm_main
SLK-100239 - Fix Race and Add Base CSPM
2 parents e7598f2 + 89a7e67 commit 5699472

File tree

19 files changed

+75
-108
lines changed

19 files changed

+75
-108
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Before using this module, ensure that you have the following:
9898
| <a name="input_aqua_volscan_api_url"></a> [aqua\_volscan\_api\_url](#input\_aqua\_volscan\_api\_url) | Aqua Volume Scanning API URL | `string` | n/a | yes |
9999
| <a name="input_aqua_volscan_aws_account_id"></a> [aqua\_volscan\_aws\_account\_id](#input\_aqua\_volscan\_aws\_account\_id) | Aqua Volume Scanning AWS Account ID | `string` | n/a | yes |
100100
| <a name="input_aqua_worker_role_arn"></a> [aqua\_worker\_role\_arn](#input\_aqua\_worker\_role\_arn) | Aqua Worker Role ARN | `string` | n/a | yes |
101+
| <a name="input_base_cspm"></a> [base\_cspm](#input\_base\_cspm) | Toggle for base CSPM only | `bool` | `false` | no |
101102
| <a name="input_create_vpcs"></a> [create\_vpcs](#input\_create\_vpcs) | Toggle to create VPCs | `bool` | `true` | no |
102103
| <a name="input_custom_agentless_role_name"></a> [custom\_agentless\_role\_name](#input\_custom\_agentless\_role\_name) | Custom Agentless role Name | `string` | `""` | no |
103104
| <a name="input_custom_bucket_name"></a> [custom\_bucket\_name](#input\_custom\_bucket\_name) | Custom bucket Name | `string` | `""` | no |
@@ -128,7 +129,6 @@ Before using this module, ensure that you have the following:
128129
| <a name="output_cspm_external_id"></a> [cspm\_external\_id](#output\_cspm\_external\_id) | Aqua CSPM External ID generated by the 'generate\_cspm\_external\_id\_function' Lambda function |
129130
| <a name="output_cspm_lambda_execution_role_arn"></a> [cspm\_lambda\_execution\_role\_arn](#output\_cspm\_lambda\_execution\_role\_arn) | The ARN of the lambda execution IAM role created for the CSPM |
130131
| <a name="output_cspm_role_arn"></a> [cspm\_role\_arn](#output\_cspm\_role\_arn) | The ARN of the IAM role created for the CSPM |
131-
| <a name="output_is_already_cspm_client"></a> [is\_already\_cspm\_client](#output\_is\_already\_cspm\_client) | Boolean indicating if the client is already a CSPM client, to be sent to the Autoconnect API |
132132
| <a name="output_kinesis_firehose_bucket_name"></a> [kinesis\_firehose\_bucket\_name](#output\_kinesis\_firehose\_bucket\_name) | Kinesis Firehose S3 Bucket Name |
133133
| <a name="output_kinesis_firehose_delivery_stream_arn"></a> [kinesis\_firehose\_delivery\_stream\_arn](#output\_kinesis\_firehose\_delivery\_stream\_arn) | Kinesis Firehose Delivery Stream ARN |
134134
| <a name="output_kinesis_firehose_role_arn"></a> [kinesis\_firehose\_role\_arn](#output\_kinesis\_firehose\_role\_arn) | Kinesis Firehose Role ARN |

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module "single" {
4141
custom_vpc_subnet_route_table2_name = var.custom_vpc_subnet_route_table2_name
4242
custom_cspm_regions = var.custom_cspm_regions
4343
volume_scanning_deployment = var.volume_scanning_deployment
44+
base_cspm = var.base_cspm
4445
}
4546

4647
module "organization" {

modules/single/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ This Terraform module provisions the essential AWS infrastructure and configurat
8181
| <a name="output_cspm_external_id"></a> [cspm\_external\_id](#output\_cspm\_external\_id) | Aqua CSPM External ID generated by the 'generate\_cspm\_external\_id\_function' Lambda function |
8282
| <a name="output_cspm_lambda_execution_role_arn"></a> [cspm\_lambda\_execution\_role\_arn](#output\_cspm\_lambda\_execution\_role\_arn) | The ARN of the lambda execution IAM role created for the CSPM |
8383
| <a name="output_cspm_role_arn"></a> [cspm\_role\_arn](#output\_cspm\_role\_arn) | The ARN of the IAM role created for the CSPM |
84-
| <a name="output_is_already_cspm_client"></a> [is\_already\_cspm\_client](#output\_is\_already\_cspm\_client) | Boolean indicating if the client is already a CSPM client, to be sent to the Autoconnect API |
8584
| <a name="output_kinesis_firehose_bucket_name"></a> [kinesis\_firehose\_bucket\_name](#output\_kinesis\_firehose\_bucket\_name) | Kinesis Firehose S3 Bucket Name |
8685
| <a name="output_kinesis_firehose_delivery_stream_arn"></a> [kinesis\_firehose\_delivery\_stream\_arn](#output\_kinesis\_firehose\_delivery\_stream\_arn) | Kinesis Firehose Delivery Stream ARN |
8786
| <a name="output_kinesis_firehose_role_arn"></a> [kinesis\_firehose\_role\_arn](#output\_kinesis\_firehose\_role\_arn) | Kinesis Firehose Role ARN |

modules/single/main.tf

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module "kinesis" {
77
aqua_volscan_api_token = var.aqua_volscan_api_token
88
custom_bucket_name = var.custom_bucket_name
99
custom_processor_lambda_role_name = var.custom_processor_lambda_role_name
10-
create_vol_scan_resource = var.volume_scanning_deployment == "true" ? true : false
10+
create_vol_scan_resource = var.volume_scanning_deployment == "true" ? true : false
1111
}
1212

1313
module "lambda" {
@@ -17,16 +17,13 @@ module "lambda" {
1717
aqua_volscan_aws_account_id = var.aqua_volscan_aws_account_id
1818
aqua_api_key = var.aqua_api_key
1919
aqua_api_secret = var.aqua_api_secret
20-
aqua_cspm_group_id = var.aqua_cspm_group_id
2120
aqua_cspm_ipv4_address = var.aqua_cspm_ipv4_address
2221
aqua_cspm_aws_account_id = var.aqua_cspm_aws_account_id
2322
aqua_cspm_url = var.aqua_cspm_url
2423
aqua_worker_role_arn = var.aqua_worker_role_arn
25-
aws_account_id = local.aws_account_id
2624
aqua_cspm_role_prefix = var.aqua_cspm_role_prefix
2725
custom_agentless_role_name = var.custom_agentless_role_name
2826
custom_cspm_role_name = var.custom_cspm_role_name
29-
custom_cspm_regions = var.custom_cspm_regions
3027
create_vol_scan_resource = var.volume_scanning_deployment == "true" ? true : false
3128
depends_on = [module.kinesis]
3229
}
@@ -52,20 +49,22 @@ module "stackset" {
5249
}
5350

5451
module "trigger" {
55-
source = "./modules/trigger"
56-
region = var.region
57-
aqua_api_key = var.aqua_api_key
58-
aqua_api_secret = var.aqua_api_secret
59-
aqua_autoconnect_url = var.aqua_autoconnect_url
60-
aqua_cspm_url = var.aqua_cspm_url
61-
aws_account_id = local.aws_account_id
62-
aqua_session_id = var.aqua_session_id
63-
cspm_role_arn = module.lambda.cspm_role_arn
64-
cspm_external_id = module.lambda.cspm_external_id
65-
is_already_cspm_client = module.lambda.is_already_cspm_client
66-
volscan_role_arn = module.lambda.agentless_role_arn
67-
volscan_external_id = module.lambda.volscan_external_id
68-
additional_tags = var.additional_tags
69-
create_vol_scan_resource = var.volume_scanning_deployment == "true" ? true : false
70-
depends_on = [module.stackset]
52+
source = "./modules/trigger"
53+
region = var.region
54+
aqua_api_key = var.aqua_api_key
55+
aqua_api_secret = var.aqua_api_secret
56+
aqua_autoconnect_url = var.aqua_autoconnect_url
57+
aqua_cspm_url = var.aqua_cspm_url
58+
aws_account_id = local.aws_account_id
59+
aqua_session_id = var.aqua_session_id
60+
cspm_role_arn = module.lambda.cspm_role_arn
61+
cspm_external_id = module.lambda.cspm_external_id
62+
volscan_role_arn = module.lambda.agentless_role_arn
63+
volscan_external_id = module.lambda.volscan_external_id
64+
additional_tags = var.additional_tags
65+
create_vol_scan_resource = var.volume_scanning_deployment == "true" ? true : false
66+
cspm_group_id = var.aqua_cspm_group_id
67+
custom_cspm_regions = var.custom_cspm_regions
68+
base_cspm = var.base_cspm
69+
depends_on = [module.stackset]
7170
}

modules/single/modules/lambda/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ No modules.
6666
| <a name="output_cspm_external_id"></a> [cspm\_external\_id](#output\_cspm\_external\_id) | Aqua CSPM External ID generated by the 'generate\_cspm\_external\_id\_function' Lambda function |
6767
| <a name="output_cspm_lambda_execution_role_arn"></a> [cspm\_lambda\_execution\_role\_arn](#output\_cspm\_lambda\_execution\_role\_arn) | The ARN of the lambda execution IAM role created for the CSPM |
6868
| <a name="output_cspm_role_arn"></a> [cspm\_role\_arn](#output\_cspm\_role\_arn) | The ARN of the IAM role created for the CSPM |
69-
| <a name="output_is_already_cspm_client"></a> [is\_already\_cspm\_client](#output\_is\_already\_cspm\_client) | Boolean indicating if the client is already a CSPM client, to be sent to the Autoconnect API |
7069
| <a name="output_volscan_external_id"></a> [volscan\_external\_id](#output\_volscan\_external\_id) | Aqua Volume Scanning External ID generated by the 'generate\_volscan\_external\_id\_function' Lambda function |
71-
<!-- END_TF_DOCS -->
70+
<!-- END_TF_DOCS -->

modules/single/modules/lambda/data.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# modules/single/modules/lambda/data.tf
22

3-
# Archive create_cspm_key.py into a zip file
4-
data "archive_file" "create_cspm_key_function" {
5-
type = "zip"
6-
source_file = "${path.module}/functions/create_cspm_key.py"
7-
output_path = "create_cspm_key.zip"
8-
}
9-
103
# Archive generate_external_id.py into a zip file
114
data "archive_file" "generate_external_id_function" {
125
type = "zip"

modules/single/modules/lambda/functions/create_cspm_key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import time
55
import hmac
66

7+
# This Lambda isn't used currently, but it is kept for future use.
8+
79
def handler(event, context):
810
cspm_url = event.get('ApiUrl')
911
aqua_api_key = event.get('AquaApiKey')

modules/single/modules/lambda/locals.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ locals {
44
# Decode the results of Lambda function invocations
55
cspm_external_id = jsondecode(aws_lambda_invocation.generate_cspm_external_id_function.result)["ExternalId"]
66
volscan_external_id = try(jsondecode(aws_lambda_invocation.generate_volscan_external_id_function[0].result)["ExternalId"], "")
7-
is_already_cspm_client = jsondecode(aws_lambda_invocation.create_cspm_key_function.result)["IsAlreadyCSPMClient"]
87
}

modules/single/modules/lambda/main.tf

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -442,38 +442,3 @@ resource "time_sleep" "sleep" {
442442
}
443443
depends_on = [aws_iam_role.cspm_role]
444444
}
445-
446-
# Create CSPM key lambda function
447-
resource "aws_lambda_function" "create_cspm_key_function" {
448-
architectures = ["x86_64"]
449-
description = "Trigger CSPM via CSPM Api"
450-
function_name = "aqua-autoconnect-create-cspm-key-function-${var.random_id}"
451-
handler = "create_cspm_key.handler"
452-
role = aws_iam_role.cspm_lambda_execution_role.arn
453-
runtime = "python3.12"
454-
timeout = 120
455-
filename = data.archive_file.create_cspm_key_function.output_path
456-
source_code_hash = data.archive_file.create_cspm_key_function.output_base64sha256
457-
tracing_config {
458-
mode = "Active"
459-
}
460-
}
461-
462-
# Invoking CSPM key lambda function
463-
resource "aws_lambda_invocation" "create_cspm_key_function" {
464-
function_name = aws_lambda_function.create_cspm_key_function.function_name
465-
input = jsonencode({
466-
ApiUrl = var.aqua_cspm_url
467-
AquaApiKey = var.aqua_api_key
468-
AquaSecretKey = var.aqua_api_secret
469-
RoleArn = aws_iam_role.cspm_role.arn
470-
ExternalId = local.cspm_external_id
471-
AccountId = tostring(var.aws_account_id)
472-
GroupId = var.aqua_cspm_group_id
473-
CustomCSPMRegions = var.custom_cspm_regions
474-
})
475-
triggers = {
476-
always_run = timestamp()
477-
}
478-
depends_on = [time_sleep.sleep]
479-
}

modules/single/modules/lambda/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ output "volscan_external_id" {
1010
value = local.volscan_external_id
1111
}
1212

13-
output "is_already_cspm_client" {
14-
description = "Boolean indicating if the client is already a CSPM client, to be sent to the Autoconnect API"
15-
value = local.is_already_cspm_client
16-
}
17-
1813
output "cspm_lambda_execution_role_arn" {
1914
description = "The ARN of the lambda execution IAM role created for the CSPM"
2015
value = aws_iam_role.cspm_lambda_execution_role.arn

0 commit comments

Comments
 (0)