-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssmRoles.py
111 lines (102 loc) · 3.06 KB
/
ssmRoles.py
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
from troposphere import (
Join,
Ref,
Template,
Output,
GetAtt,
Export
)
import troposphere.iam as iam
from cfn_flip import flip, to_yaml
t = Template()
def main():
# Meta
t.add_version("2010-09-09")
t.add_description("SSM EC2 and SSM Automation roles")
t.add_metadata({
"Comments": "Development",
"LastUpdated": "2017 02 16",
"UpdatedBy": "Hamin Mousavi",
"Version": "0.1",
})
# EC2 instance role
ec2_role_for_ssm = t.add_resource(
iam.Role(
"AmazonEC2RoleforSSM",
Path="/",
AssumeRolePolicyDocument=
{
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com",
"ssm.amazonaws.com"
]
},
"Action": ["sts:AssumeRole"]
}
]
},
ManagedPolicyArns=[
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
],
)
)
ec2_role_for_ssm_instance_profile = t.add_resource(iam.InstanceProfile(
"InstanceProfile",
Roles=[Ref("AmazonEC2RoleforSSM")]
))
# Automation service role
automation_service_role = t.add_resource(
iam.Role(
"AutomationServiceRole",
Path="/",
AssumeRolePolicyDocument=
{
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com",
"ssm.amazonaws.com"
]
},
"Action": ["sts:AssumeRole", # TODO
"iam:PassRole"] # Has to passrole to itself and the ec2-instance role
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/sysman-ami-permissions.html
}
]
},
ManagedPolicyArns=[
"arn:aws:iam::aws:policy/service-role/AmazonSSMAutomationRole"
],
)
)
# Maintenance window role
maintenance_window_role = t.add_resource(
iam.Role(
"MaintenanceWindowRole",
Path="/",
AssumeRolePolicyDocument=
{
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com",
"ssm.amazonaws.com"
]
},
"Action": ["sts:AssumeRole"]
}
]
},
ManagedPolicyArns=[
"arn:aws:iam::aws:policy/service-role/AmazonSSMMaintenanceWindowRole"
],
)
)
print(to_yaml(t.to_json()))
if __name__ == '__main__':
main()