-
Notifications
You must be signed in to change notification settings - Fork 1
/
roles.tf
89 lines (79 loc) · 2.37 KB
/
roles.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
81
82
83
84
85
86
87
88
89
data "aws_iam_policy_document" "awsvpn_policy" {
statement {
effect = "Allow"
actions = [
"ssm:GetParameter",
"ssm:PutParameter",
"ssm:GetParametersByPath"
]
resources = ["arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.company_name}/awsvpn/${local.ssm_environment}/*"]
}
statement {
effect = "Allow"
actions = [
"sns:Publish",
"ec2:DetachNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeTags",
"ec2:AttachNetworkInterface",
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"s3:GetObject",
"s3:ListObjects"
]
resources = [
"arn:aws:s3:::${var.company_name}-instance-config-awsvpn-${var.environment}/*"
]
}
statement {
effect = "Allow"
actions = [
"s3:ListBucket"
]
resources = [
"arn:aws:s3:::${var.company_name}-instance-config-awsvpn-${var.environment}"
]
}
}
data "aws_iam_policy_document" "awsvpn_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
]
}
}
}
resource "aws_iam_policy" "awsvpn_policy" {
name = "${var.environment}-awsvpn-policy"
description = "AWSVPN-Instance Policy for ${var.environment}"
policy = data.aws_iam_policy_document.awsvpn_policy.json
}
resource "aws_iam_role" "awsvpn_role" {
name = "${var.environment}-awsvpn-role"
assume_role_policy = data.aws_iam_policy_document.awsvpn_role.json
force_detach_policies = true
tags = merge(local.global_tags)
}
data "aws_iam_policy" "CloudWatchAgentServerPolicy" {
arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}
resource "aws_iam_role_policy_attachment" "awsvpn-cwagent-role-policy-attach" {
role = aws_iam_role.awsvpn_role.name
policy_arn = data.aws_iam_policy.CloudWatchAgentServerPolicy.arn
}
resource "aws_iam_role_policy_attachment" "awsvpn-manual-role-policy-attach" {
role = aws_iam_role.awsvpn_role.name
policy_arn = aws_iam_policy.awsvpn_policy.arn
}
resource "aws_iam_instance_profile" "awsvpn_profile" {
name = "${var.environment}-awsvpn-profile"
role = aws_iam_role.awsvpn_role.name
}