-
Notifications
You must be signed in to change notification settings - Fork 334
/
apps.py
64 lines (51 loc) · 2.57 KB
/
apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Copyright 2017-present Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from streamalert_cli.terraform.lambda_module import generate_lambda
def generate_apps(cluster_name, cluster_dict, config):
"""Add the app integrations module to the Terraform cluster dict.
Args:
cluster_name (str): The name of the currently generating cluster
cluster_dict (defaultdict): The dict containing all Terraform config for
a given cluster.
config (dict): The loaded config from the 'conf/' directory
Returns:
bool: Result of applying the app integration module
"""
prefix = config['global']['account']['prefix']
for function_name, app_info in config['clusters'][cluster_name]['modules'].get(
'streamalert_apps', {}).items():
tf_module_prefix = 'app_{}_{}'.format(app_info['app_name'], cluster_name)
destination_func = '{}_{}_streamalert_classifier'.format(prefix, cluster_name)
app_config = {
'app_type': app_info['type'],
'destination_function_name': destination_func,
'schedule_expression': app_info['schedule_expression']
}
# Format the iam module with 'app_<app_name_<cluster>_iam'
cluster_dict['module']['{}_iam'.format(tf_module_prefix)] = {
'account_id': config['global']['account']['aws_account_id'],
'destination_function_name': destination_func,
'function_name': function_name,
'region': config['global']['account']['region'],
'function_role_id': '${{module.{}_lambda.role_id}}'.format(tf_module_prefix),
'source': './modules/tf_app_iam'
}
# Format the lambda module with 'app_<app_name_<cluster>_lambda'
cluster_dict['module']['{}_lambda'.format(tf_module_prefix)] = generate_lambda(
function_name,
'streamalert.apps.main.handler',
config['clusters'][cluster_name]['modules']['streamalert_apps'][function_name],
config,
input_event=app_config,
include_layers=True,
)