From b3d3fb6a75a0dd9a8def5f1a913300d22cbb9b00 Mon Sep 17 00:00:00 2001 From: Jack Naglieri Date: Mon, 24 Apr 2017 17:21:27 -0700 Subject: [PATCH] [tf] support SNS as an input, and arbitrary S3/Lambda functions as outputs --- conf/inputs.json | 5 +++ conf/outputs.json | 27 +++++++++------- stream_alert_cli/runner.py | 3 +- terraform/modules/tf_stream_alert/iam.tf | 31 +++++++++++++++++-- terraform/modules/tf_stream_alert/main.tf | 11 +++++++ terraform/modules/tf_stream_alert/sns.tf | 8 +++++ .../modules/tf_stream_alert/variables.tf | 15 +++++++++ terraform/variables.tf | 31 ++++++++++++++----- 8 files changed, 107 insertions(+), 24 deletions(-) create mode 100644 conf/inputs.json diff --git a/conf/inputs.json b/conf/inputs.json new file mode 100644 index 000000000..4dfbea761 --- /dev/null +++ b/conf/inputs.json @@ -0,0 +1,5 @@ +{ + "aws-sns": { + "sample_sns": "arn:aws:sns:us-region-1:111111111111:topicname" + } +} \ No newline at end of file diff --git a/conf/outputs.json b/conf/outputs.json index 90807833b..325ee12e8 100644 --- a/conf/outputs.json +++ b/conf/outputs.json @@ -1,14 +1,17 @@ { - "aws-s3": { - "sample.bucket": "sample_bucket_name" - }, - "pagerduty": [ - "sample_integration" - ], - "phantom": [ - "sample_integration" - ], - "slack": [ - "sample_channel" - ] + "aws-s3": { + "sample.bucket": "sample_bucket_name" + }, + "aws-lambda": { + "sample_lambda": "arn:aws:lambda:region:account-id:function:function-name" + }, + "pagerduty": [ + "sample_integration" + ], + "phantom": [ + "sample_integration" + ], + "slack": [ + "sample_channel" + ] } \ No newline at end of file diff --git a/stream_alert_cli/runner.py b/stream_alert_cli/runner.py index eab707f38..f8e6dad7e 100644 --- a/stream_alert_cli/runner.py +++ b/stream_alert_cli/runner.py @@ -204,7 +204,8 @@ def tf_runner(**kwargs): refresh_state = kwargs.get('refresh_state', True) tf_action_index = 1 # The index to the terraform 'action' - tf_opts = ['-var-file=../{}'.format(CONFIG.filename)] + var_files = {CONFIG.filename, 'conf/outputs.json', 'conf/inputs.json'} + tf_opts = ['-var-file=../{}'.format(x) for x in var_files] tf_targets = ['-target={}'.format(x) for x in targets] tf_command = ['terraform', 'plan'] + tf_opts + tf_targets if action == 'destroy': diff --git a/terraform/modules/tf_stream_alert/iam.tf b/terraform/modules/tf_stream_alert/iam.tf index fe8abe5c1..e13c78319 100644 --- a/terraform/modules/tf_stream_alert/iam.tf +++ b/terraform/modules/tf_stream_alert/iam.tf @@ -146,8 +146,9 @@ EOF // Allow the Alert Processor to invoke Lambda resource "aws_iam_role_policy" "streamalert_alert_processor_lambda" { - name = "${var.prefix}_${var.cluster}_streamalert_alert_processor_lambda" - role = "${aws_iam_role.streamalert_alert_processor_role.id}" + count = "${length(keys(var.output_lambda_functions))}" + name = "${var.prefix}_${var.cluster}_streamalert_alert_processor_lambda_${element(keys(var.output_lambda_functions), count.index)}" + role = "${aws_iam_role.streamalert_alert_processor_role.id}" policy = <