forked from evildotuk/terraform-aws-pritunl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
49 lines (35 loc) · 1.32 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
data "aws_iam_policy_document" "assume_role" {
count = var.aws_iam_instance_profile == "" ? 1 : 0
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "ec2_ssm_role" {
count = var.aws_iam_instance_profile == "" ? 1 : 0
name = "${var.resource_name_prefix}-ec2-ssm-role"
path = "/"
assume_role_policy = data.aws_iam_policy_document.assume_role[0].json
}
resource "aws_iam_role_policy_attachment" "ssm_policy_attach" {
count = var.aws_iam_instance_profile == "" ? 1 : 0
role = aws_iam_role.ec2_ssm_role[0].name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
depends_on = [aws_iam_role.ec2_ssm_role]
}
# resource "aws_iam_role_policy_attachment" "vpc_policy_attach" {
# count = var.aws_iam_instance_profile == "" ? 1 : 0
# role = aws_iam_role.ec2_ssm_role[0].name
# policy_arn = "arn:aws:iam::aws:policy/AmazonVPCFullAccess"
# depends_on = [aws_iam_role.ec2_ssm_role]
# }
resource "aws_iam_instance_profile" "ssm_profile" {
count = var.aws_iam_instance_profile == "" ? 1 : 0
name = "${var.resource_name_prefix}-ec2-ssm-role"
role = aws_iam_role.ec2_ssm_role[0].name
depends_on = [aws_iam_role.ec2_ssm_role]
}