-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
80 lines (63 loc) · 1.97 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module "iam_assumable_role_ssm" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = "v5.44.0"
create_role = var.create_role
create_instance_profile = var.create_instance_profile
role_name = "${local.full_service_name}-role"
role_description = "IAM Role for ${local.full_service_name}"
role_requires_mfa = var.role_requires_mfa
# https://aws.amazon.com/blogs/security/announcing-an-update-to-iam-role-trust-policy-behavior/
allow_self_assume_role = var.allow_self_assume_role
trusted_role_services = [
"ec2.amazonaws.com"
]
custom_role_policy_arns = concat(
var.additional_iam_policies,
[
"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
]
)
tags = merge(
{
},
local.tags_app_module
)
}
data "aws_iam_policy_document" "this" {
statement {
sid = "AllowStartSessionForEnv"
effect = "Allow"
actions = ["ssm:StartSession"]
resources = ["arn:aws:ec2:*:*:instance/*"]
condition {
test = "StringEquals"
variable = "aws:ResourceTag/environment"
values = var.environment == "prd" ? ["prd"] : ["tst", "dev", "acc", "qa", "prv", "stg", "qas"]
}
}
statement {
sid = "AllowPortForwardingViaDocument"
effect = "Allow"
actions = ["ssm:StartSession"]
resources = ["arn:aws:ssm:*:*:document/AWS-StartPortForwardingSessionToRemoteHost"]
}
statement {
sid = "AllowResumeAndTerminateSession"
effect = "Allow"
actions = ["ssm:ResumeSession", "ssm:TerminateSession"]
resources = ["arn:aws:ssm:*:*:session/*"]
}
}
module "iam_policy_ssm_connect" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = "v5.44.0"
name = "${local.full_service_name}-default"
path = "/"
description = "IAM Policy for establishing ssm connection"
policy = data.aws_iam_policy_document.this.json
tags = merge(
{
},
local.tags_app_module
)
}