Skip to content

Commit c2c0605

Browse files
SD-2156. Environment and Slack variables
2 parents f434b58 + 6d4c92a commit c2c0605

File tree

11 files changed

+328
-243
lines changed

11 files changed

+328
-243
lines changed

asg.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ASG notification
22
resource "aws_autoscaling_notification" "manage_dns_asg_notification" {
3+
count = var.enabled ? 1 : 0
4+
35
group_names = var.asg_names
46

57
notifications = [
@@ -8,6 +10,6 @@ resource "aws_autoscaling_notification" "manage_dns_asg_notification" {
810
"autoscaling:EC2_INSTANCE_TERMINATE",
911
]
1012

11-
topic_arn = aws_sns_topic.dns.arn
13+
topic_arn = join("", aws_sns_topic.manage_dns_asg_sns.*.arn)
1214
}
1315

aws.tf

Lines changed: 0 additions & 2 deletions
This file was deleted.

iam.tf

Lines changed: 99 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,101 @@
1-
# Lambda policy
2-
data "aws_iam_policy_document" "lambda" {
3-
statement {
4-
actions = [
5-
"route53:GetHostedZone",
6-
"route53:ChangeResourceRecordSets",
7-
"route53:ListResourceRecordSets",
8-
]
9-
10-
resources = [
11-
"arn:aws:route53:::hostedzone/${var.zone_id}",
12-
]
13-
}
14-
15-
statement {
16-
actions = [
17-
"autoscaling:DescribeAutoScalingGroups",
18-
"autoscaling:DescribeAutoScalingInstances",
19-
]
20-
21-
resources = [
22-
"*",
23-
]
24-
}
25-
26-
statement {
27-
actions = [
28-
"ec2:DescribeInstances",
29-
]
30-
31-
resources = [
32-
"*",
33-
]
34-
}
35-
36-
statement {
37-
actions = [
38-
"sts:AssumeRole",
39-
]
40-
41-
resources = [
42-
"*",
43-
]
44-
}
1+
# Lambda policy for logging
2+
resource "aws_iam_role_policy" "lambda_manage_dns_logging_policy" {
3+
count = var.enabled ? 1 : 0
4+
5+
name = "${var.service}_lambda_dns_logging_policy"
6+
role = join("", aws_iam_role.lambda_manage_dns_role.*.id)
7+
8+
policy = <<EOF
9+
{
10+
"Version": "2012-10-17",
11+
"Statement": [
12+
{
13+
"Effect": "Allow",
14+
"Action": [
15+
"logs:CreateLogGroup",
16+
"logs:CreateLogStream",
17+
"logs:PutLogEvents"
18+
],
19+
"Resource": "*"
20+
}
21+
]
22+
}
23+
EOF
24+
25+
}
26+
27+
# Lambda policy for managing dns
28+
resource "aws_iam_role_policy" "lambda_manage_dns_policy" {
29+
count = var.enabled ? 1 : 0
30+
31+
name = "${var.service}_lambda_route53_policy"
32+
role = join("", aws_iam_role.lambda_manage_dns_role.*.id)
33+
34+
policy = <<EOF
35+
{
36+
"Version": "2012-10-17",
37+
"Statement": [
38+
{
39+
"Effect": "Allow",
40+
"Action": [
41+
"route53:GetHostedZone",
42+
"route53:ChangeResourceRecordSets",
43+
"route53:ListResourceRecordSets"
44+
],
45+
"Resource": "arn:aws:route53:::hostedzone/${var.zone_id}"
46+
},
47+
{
48+
"Effect": "Allow",
49+
"Action": [
50+
"autoscaling:DescribeAutoScalingGroups",
51+
"autoscaling:DescribeAutoScalingInstances"
52+
],
53+
"Resource": "*"
54+
},
55+
{
56+
"Effect": "Allow",
57+
"Action": [
58+
"ec2:DescribeInstances"
59+
],
60+
"Resource": "*"
61+
}
62+
]
63+
}
64+
EOF
65+
66+
}
67+
68+
# Lambda role
69+
resource "aws_iam_role" "lambda_manage_dns_role" {
70+
count = var.enabled ? 1 : 0
71+
72+
name_prefix = "${var.service}_lambda_dns"
73+
74+
assume_role_policy = <<EOF
75+
{
76+
"Version": "2012-10-17",
77+
"Statement": [
78+
{
79+
"Action": "sts:AssumeRole",
80+
"Principal": {
81+
"Service": "lambda.amazonaws.com"
82+
},
83+
"Effect": "Allow",
84+
"Sid": ""
85+
}
86+
]
87+
}
88+
EOF
89+
90+
}
91+
92+
resource "aws_lambda_permission" "manage_dns_asg_sns" {
93+
count = var.enabled ? 1 : 0
94+
95+
statement_id = "AllowExecutionFromSNS"
96+
action = "lambda:InvokeFunction"
97+
function_name = join("", aws_lambda_function.manage_dns.*.arn)
98+
principal = "sns.amazonaws.com"
99+
source_arn = join("", aws_sns_topic.manage_dns_asg_sns.*.arn)
45100
}
46101

include/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip

0 commit comments

Comments
 (0)