// createRole will create requested IAM role
createRole will create requested IAM role
// createRole will create requested IAM role
func (s *IAMService) createRole(roleName string, roleType string, params interface{}) error {
	l := s.log.WithValues("role_name", roleName)
	i := &awsiam.GetRoleInput{
		RoleName: aws.String(roleName),
	}
	_, err := s.iamClient.GetRole(i)
	if IsNotFound(err) {
		tmpl := gentTrustPolicyTemplate(roleType)
		assumeRolePolicyDocument, err := generatePolicyDocument(tmpl, params)
		if err != nil {
			l.Error(err, "failed to generate assume policy document from template for IAM role")
			return err
		}
		tags := []*awsiam.Tag{
			{
				Key:   aws.String(IAMControllerOwnedTag),
				Value: aws.String(""),
			},
			{
				Key:   aws.String(fmt.Sprintf(ClusterIDTag, s.clusterName)),
				Value: aws.String("owned"),
			},
		}
		i := &awsiam.CreateRoleInput{
			RoleName:                 aws.String(roleName),
			AssumeRolePolicyDocument: aws.String(assumeRolePolicyDocument),
			Tags:                     tags,
		}
		_, err = s.iamClient.CreateRole(i)
		if err != nil {
			l.Error(err, "failed to create IAM Role")
			return err
		}
		i2 := &awsiam.CreateInstanceProfileInput{
			InstanceProfileName: aws.String(roleName),
			Tags:                tags,
		}
		_, err = s.iamClient.CreateInstanceProfile(i2)
		if IsAlreadyExists(err) {
		} else if err != nil {
			l.Error(err, "failed to create instance profile")
			return err
		}
		i3 := &awsiam.AddRoleToInstanceProfileInput{
			InstanceProfileName: aws.String(roleName),
			RoleName:            aws.String(roleName),
		}
		_, err = s.iamClient.AddRoleToInstanceProfile(i3)
		if IsAlreadyExists(err) {
		} else if err != nil {
			l.Error(err, "failed to add role to instance profile")
			return err
		}
		l.Info("successfully created a new IAM role")
	} else if err != nil {
		l.Error(err, "Failed to fetch IAM Role")
		return err
	} else {
		l.Info("IAM Role already exists, skipping creation")
	}
	return nil
}
func ( s * IAMService ) createRole ( roleName string , roleType string , params interface { } ) error { l := s . log . WithValues ( " " , roleName ) i := & awsiam . GetRoleInput { RoleName : aws . String ( roleName ) , } _ , err := s . iamClient . GetRole ( i ) if IsNotFound ( err ) { tmpl := gentTrustPolicyTemplate ( roleType ) assumeRolePolicyDocument , err := generatePolicyDocument ( tmpl , params ) if err != nil { l . Error ( err , " " ) return err } tags := [ ] * awsiam . Tag { { Key : aws . String ( IAMControllerOwnedTag ) , Value : aws . String ( " " ) , } , { Key : aws . String ( fmt . Sprintf ( ClusterIDTag , s . clusterName ) ) , Value : aws . String ( " " ) , } , } i := & awsiam . CreateRoleInput { RoleName : aws . String ( roleName ) , AssumeRolePolicyDocument : aws . String ( assumeRolePolicyDocument ) , Tags : tags , } _ , err = s . iamClient . CreateRole ( i ) if err != nil { l . Error ( err , " " ) return err } i2 := & awsiam . CreateInstanceProfileInput { InstanceProfileName : aws . String ( roleName ) , Tags : tags , } _ , err = s . iamClient . CreateInstanceProfile ( i2 ) if IsAlreadyExists ( err ) { } else if err != nil { l . Error ( err , " " ) return err } i3 := & awsiam . AddRoleToInstanceProfileInput { InstanceProfileName : aws . String ( roleName ) , RoleName : aws . String ( roleName ) , } _ , err = s . iamClient . AddRoleToInstanceProfile ( i3 ) if IsAlreadyExists ( err ) { } else if err != nil { l . Error ( err , " " ) return err } l . Info ( " " ) } else if err != nil { l . Error ( err , " " ) return err } else { l . Info ( " " ) } return nil }
createRole will create requested IAM role
createRole will create requested IAM role
// create new IAMRole if it does not exists yet // fall thru // fall thru