Skip to content

Commit 3fa61fa

Browse files
committed
wip
1 parent 7013151 commit 3fa61fa

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

stacker_blueprints/iam_roles.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,68 @@ def create_template(self):
227227
self.create_lambda_role(role)
228228

229229
self.create_policy()
230+
231+
class IAMRole(RoleBaseBlueprint):
232+
"""
233+
Blueprint to create an IAM role.
234+
235+
- class_path: stacker_blueprints.iam_roles.IAMRole
236+
name: my-role
237+
variables:
238+
AttachedPolicies:
239+
- arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
240+
Name: myRole
241+
Path: /
242+
AssumeRole:
243+
- arn:aws:user/alphonse
244+
"""
245+
VARIABLES = {
246+
"AttachedPolicies": {
247+
"type": list,
248+
"description": "List of ARNs of policies to attach",
249+
"default": [],
250+
},
251+
"Name": {
252+
"type": str,
253+
"description": "The name of the role",
254+
"default": "Role",
255+
},
256+
"Path": {
257+
"type": str,
258+
"description": "Provide the path",
259+
"default": "/",
260+
},
261+
"AssumeRole": {
262+
"type": list,
263+
"description": "List of ARNs of entities allowed to assume this role",
264+
"default": [],
265+
},
266+
}
267+
268+
def create_role(self, name, assumerole_policy):
269+
variables = self.get_variables()
270+
271+
role = t.add_resource(
272+
iam.Role(
273+
name,
274+
Path=variables['Path'],
275+
AssumeRolePolicyDocument=assumerole_policy,
276+
ManagedPolicyArns=variables['AttachedPolicies'],
277+
)
278+
)
279+
280+
t.add_output(
281+
Output(name + "RoleName", Value=Ref(role))
282+
)
283+
284+
t.add_output(
285+
Output(name + "RoleArn", Value=GetAtt(role.title, "Arn"))
286+
)
287+
288+
self.roles.append(role)
289+
return role
290+
291+
def create_template(self):
292+
variables = self.get_variables()
293+
self.create_ec2_role(variables["Name"])
294+
self.create_policy(variables["Name"])

0 commit comments

Comments
 (0)