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