-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.tf
59 lines (56 loc) · 1.81 KB
/
handler.tf
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
module "k3s-mysql-interruption-handler" {
source = "git::https://github.com/PiotrKuligowski/terraform-aws-spot-mysql-interruption-handler.git"
function_name = "${var.project}-mysql-interruption-handler"
component = "mysql-interruption-handler"
project = var.project
environment_vars = local.mysql_interruption_handler_env_variables
policy_statements = local.mysql_interruption_handler_policy_statements
eventbridge_trigger = local.spot_interruption_event_pattern
tags = var.tags
}
locals {
mysql_interruption_handler_env_variables = {
REGION = data.aws_region.current.name
MYSQL_USER = "root"
MYSQL_PASSWORD = random_password.this.result
VOLUME_ID = local.ebs_id
AUTOSCALING_GROUP_NAME = module.this.asg_name
}
spot_interruption_event_pattern = <<PATTERN
{
"detail-type": ["EC2 Spot Instance Interruption Warning"],
"source": ["aws.ec2"]
}
PATTERN
mysql_interruption_handler_policy_statements = {
AllowAttachAndDescribe = {
effect = "Allow",
actions = [
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DetachInstances",
"ssm:ListCommandInvocations",
"ec2:DescribeInstances",
"ec2:TerminateInstances"
]
resources = ["*"]
}
AllowAttachAndDescribe2 = {
sid = "AllowAttachAndDescribe2"
effect = "Allow"
actions = [
"ec2:DetachVolume",
"ec2:DescribeVolumes",
"ec2:DescribeInstances",
"ec2:TerminateInstances",
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DetachInstances"
]
resources = ["*"]
}
AllowLogs = {
effect = "Allow",
actions = ["logs:*"]
resources = ["arn:aws:logs:*:*:*"]
}
}
}