@@ -228,26 +228,22 @@ def create_template(self):
228228
229229 self .create_policy ()
230230
231- class IAMRole (RoleBaseBlueprint ):
231+
232+ class IAMRole (Blueprint ):
232233 """
233234 Blueprint to create an IAM role.
234235
235236 - class_path: stacker_blueprints.iam_roles.IAMRole
236237 name: my-role
237238 variables:
238- AttachedPolicies:
239- - arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
240239 Name: myRole
241240 Path: /
241+ AttachedPolicies:
242+ - arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
242243 AssumeRole:
243- - arn:aws:user/alphonse
244+ - arn:aws:iam::123456789012: user/JohnDoe
244245 """
245246 VARIABLES = {
246- "AttachedPolicies" : {
247- "type" : list ,
248- "description" : "List of ARNs of policies to attach" ,
249- "default" : [],
250- },
251247 "Name" : {
252248 "type" : str ,
253249 "description" : "The name of the role" ,
@@ -258,37 +254,43 @@ class IAMRole(RoleBaseBlueprint):
258254 "description" : "Provide the path" ,
259255 "default" : "/" ,
260256 },
257+ "AttachedPolicies" : {
258+ "type" : list ,
259+ "description" : "List of ARNs of policies to attach" ,
260+ "default" : [],
261+ },
261262 "AssumeRole" : {
262263 "type" : list ,
263264 "description" : "List of ARNs of entities allowed to assume this role" ,
264265 "default" : [],
265266 },
266267 }
267268
268- def create_role (self , name , assumerole_policy ):
269+ def create_template (self ):
269270 variables = self .get_variables ()
270271
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 (
272282 iam .Role (
273- name ,
283+ variables [ 'Name' ] ,
274284 Path = variables ['Path' ],
275- AssumeRolePolicyDocument = assumerole_policy ,
276285 ManagedPolicyArns = variables ['AttachedPolicies' ],
286+ AssumeRolePolicyDocument = ar_policy ,
277287 )
278288 )
279289
280- t .add_output (
290+ self . template .add_output (
281291 Output (name + "RoleName" , Value = Ref (role ))
282292 )
283293
284- t .add_output (
294+ self . template .add_output (
285295 Output (name + "RoleArn" , Value = GetAtt (role .title , "Arn" ))
286296 )
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