-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiam.tf
More file actions
114 lines (97 loc) · 2.2 KB
/
Copy pathiam.tf
File metadata and controls
114 lines (97 loc) · 2.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
resource "aws_iam_role" "ecs_service" {
name = "tf_ecs_role"
assume_role_policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy" "ecs_service" {
name = "tf_ecs_policy"
role = aws_iam_role.ecs_service.name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:Describe*",
"elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
"elasticloadbalancing:DeregisterTargets",
"elasticloadbalancing:Describe*",
"elasticloadbalancing:RegisterInstancesWithLoadBalancer",
"elasticloadbalancing:RegisterTargets"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "app" {
name = "tf-${var.base_name}-ecs-instprofile"
role = aws_iam_role.app_instance.name
}
resource "aws_iam_role" "app_instance" {
name = "tf-${var.base_name}-ecs-instance-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
data "template_file" "instance_profile" {
template = file("${path.module}/instance-profile-policy.json")
vars = {
app_log_group_arn = aws_cloudwatch_log_group.app.arn
ecs_log_group_arn = aws_cloudwatch_log_group.ecs.arn
}
}
resource "aws_iam_role_policy" "instance" {
name = "TfEcsExampleInstanceRole"
role = aws_iam_role.app_instance.name
policy = data.template_file.instance_profile.rendered
}
resource "aws_iam_role" "lambda_iam" {
name = "iam_for_lambda"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "lamba_exec_role_eni" {
role = aws_iam_role.lambda_iam.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}