File tree Expand file tree Collapse file tree 7 files changed +21
-18
lines changed Expand file tree Collapse file tree 7 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ module "asg_lambda_role" {
15
15
source = "github.com/corelight/terraform-aws-sensor//modules/iam/lambda"
16
16
17
17
lambda_cloudwatch_log_group_arn = module.sensor.cloudwatch_log_group_arn
18
- sensor_autoscaling_group_name = module.sensor.autoscaling_group_name
18
+ sensor_autoscaling_group_arn = module.sensor.autoscaling_group_arn
19
19
security_group_arn = module.sensor.management_security_group_arn
20
20
subnet_arn = data.aws_subnet.management.arn
21
21
}
Original file line number Diff line number Diff line change @@ -15,14 +15,20 @@ resource "aws_autoscaling_group" "sensor_asg" {
15
15
health_check_grace_period = 300
16
16
termination_policies = [" OldestInstance" ]
17
17
protect_from_scale_in = false
18
- }
18
+ wait_for_capacity_timeout = 0
19
19
20
- resource "aws_autoscaling_lifecycle_hook" "asg_scale_up_hook" {
21
- autoscaling_group_name = aws_autoscaling_group. sensor_asg . name
22
- lifecycle_transition = " autoscaling:EC2_INSTANCE_LAUNCHING"
23
- name = var. asg_lifecycle_hook_name
24
- default_result = " ABANDON"
25
- heartbeat_timeout = 300
20
+ initial_lifecycle_hook {
21
+ lifecycle_transition = " autoscaling:EC2_INSTANCE_LAUNCHING"
22
+ name = var. asg_lifecycle_hook_name
23
+ default_result = " ABANDON"
24
+ heartbeat_timeout = 300
25
+ }
26
+
27
+ depends_on = [
28
+ aws_lambda_function . auto_scaling_lambda ,
29
+ aws_cloudwatch_event_rule . asg_lifecycle_rule ,
30
+ aws_cloudwatch_log_group . log_group ,
31
+ ]
26
32
}
27
33
28
34
resource "aws_autoscaling_policy" "sensor_autoscale_policy" {
Original file line number Diff line number Diff line change @@ -38,8 +38,8 @@ resource "aws_cloudwatch_event_rule" "asg_lifecycle_rule" {
38
38
" source" : [" aws.autoscaling" ],
39
39
" detail-type" : [" EC2 Instance-launch Lifecycle Action" ],
40
40
" detail" : {
41
- " AutoScalingGroupName" : [aws_autoscaling_group.sensor_asg.name ],
42
- " LifecycleHookName" : [aws_autoscaling_lifecycle_hook.asg_scale_up_hook.name ]
41
+ " AutoScalingGroupName" : [var.sensor_asg_name ],
42
+ " LifecycleHookName" : [var.asg_lifecycle_hook_name ]
43
43
}
44
44
})
45
45
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ resource "aws_network_interface" "bastion_nic" {
29
29
}
30
30
31
31
resource "aws_eip" "bastion_public_ip" {
32
+ instance = aws_instance. bastion . id
32
33
network_interface = aws_network_interface. bastion_nic . id
33
34
34
35
tags = merge ({ Name : " ${ var . bastion_instance_name } -public-ip" }, var. tags )
Original file line number Diff line number Diff line change 1
- data "aws_autoscaling_group" "asg" {
2
- name = var. sensor_autoscaling_group_name
3
- }
4
-
5
1
data "aws_iam_policy_document" "lambda_nic_manager_policy" {
6
2
statement {
7
3
effect = " Allow"
@@ -31,7 +27,7 @@ data "aws_iam_policy_document" "lambda_nic_manager_policy" {
31
27
" autoscaling:CompleteLifecycleAction"
32
28
]
33
29
resources = [
34
- data . aws_autoscaling_group . asg . arn
30
+ var . sensor_autoscaling_group_arn
35
31
]
36
32
}
37
33
@@ -46,7 +42,7 @@ data "aws_iam_policy_document" "lambda_nic_manager_policy" {
46
42
]
47
43
condition {
48
44
test = " StringEquals"
49
- values = [data . aws_autoscaling_group . asg . name ]
45
+ values = [split ( " / " , var . sensor_autoscaling_group_arn )[ 1 ] ]
50
46
variable = " aws:ResourceTag/aws:autoscaling:groupName"
51
47
}
52
48
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ variable "lambda_cloudwatch_log_group_arn" {
3
3
type = string
4
4
}
5
5
6
- variable "sensor_autoscaling_group_name " {
6
+ variable "sensor_autoscaling_group_arn " {
7
7
description = " ARN of the sensor EC2 autoscaling group of Corelight sensors"
8
8
type = string
9
9
}
Original file line number Diff line number Diff line change 1
- output "auto_scale_group_arn " {
1
+ output "autoscaling_group_arn " {
2
2
value = aws_autoscaling_group. sensor_asg . arn
3
3
}
4
4
You can’t perform that action at this time.
0 commit comments