-
Notifications
You must be signed in to change notification settings - Fork 5
/
iam.tf
40 lines (31 loc) · 1.04 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
data "aws_iam_policy_document" "instance_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "random_id" "iam_id" {
byte_length = 8
}
resource "aws_iam_role" "instance" {
name = "tyk_gateway_instance_${random_id.iam_id.hex}"
path = "/system/"
assume_role_policy = data.aws_iam_policy_document.instance_assume_role.json
}
resource "aws_iam_role_policy_attachment" "ssm_role_policy" {
role = aws_iam_role.instance.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
count = var.enable_ssm ? 1 : 0
}
resource "aws_iam_role_policy_attachment" "cloudwatch_agent_instance_role" {
role = aws_iam_role.instance.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
count = var.enable_cloudwatch_policy ? 1 : 0
}
resource "aws_iam_instance_profile" "default" {
name = "tyk_gateway_${random_id.iam_id.hex}"
role = aws_iam_role.instance.name
}