-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiam.tf
58 lines (49 loc) · 1.53 KB
/
iam.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
locals {
assumable_roles = [
for account in local.search_accounts:
"arn:aws:iam::${account}:role/${local.peering_role_name}"
]
}
data "aws_iam_policy_document" "vpc_auto_peering_lambda_assume_role_policy" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
identifiers = ["lambda.amazonaws.com"]
type = "Service"
}
}
}
data "aws_iam_policy_document" "vpc_auto_peering_lambda_policy" {
statement {
effect = "Allow"
resources = local.assumable_roles
actions = [
"sts:AssumeRole"
]
}
statement {
effect = "Allow"
resources = ["*"]
actions = [
"sts:GetCallerIdentity",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
}
}
resource "aws_iam_role" "vpc_auto_peering_lambda" {
name = "vpc-auto-peering-lambda-role-${var.region}-${var.deployment_identifier}"
assume_role_policy = data.aws_iam_policy_document.vpc_auto_peering_lambda_assume_role_policy.json
}
resource "aws_iam_policy" "vpc_auto_peering_lambda" {
name = "vpc-auto-peering-lambda-policy-${var.region}-${var.deployment_identifier}"
description = "vpc-auto-peering-lambda-policy"
policy = data.aws_iam_policy_document.vpc_auto_peering_lambda_policy.json
}
resource "aws_iam_policy_attachment" "vpc_auto_peering_lambda" {
name = "vpc-auto-peering-lambda-policy-attachment-${var.region}-${var.deployment_identifier}"
roles = [aws_iam_role.vpc_auto_peering_lambda.id]
policy_arn = aws_iam_policy.vpc_auto_peering_lambda.arn
}