@@ -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