@@ -11,10 +11,7 @@ const AWS = require('aws-sdk');
1111
1212const { ensureParameterExists } = require ( './legacy/aws-util' ) ;
1313
14- const {
15- S3_BUCKET_NAME_PREFIX ,
16- ECS_WORKER_ROLE_NAME
17- } = require ( '../aws/constants' ) ;
14+ const { S3_BUCKET_NAME_PREFIX } = require ( '../aws/constants' ) ;
1815
1916const getAccountId = require ( '../aws/aws-get-account-id' ) ;
2017
@@ -48,12 +45,11 @@ class PlatformECS {
4845
4946 async init ( ) {
5047 await setDefaultAWSCredentials ( AWS ) ;
51-
5248 this . accountId = await getAccountId ( ) ;
5349
5450 await ensureSSMParametersExist ( this . platformOpts . region ) ;
5551 await ensureS3BucketExists ( 'global' , this . s3LifecycleConfigurationRules ) ;
56- await createIAMResources ( this . accountId ) ;
52+ await createIAMResources ( this . accountId , this . platformOpts . taskRoleName ) ;
5753 }
5854
5955 async createWorker ( ) { }
@@ -112,19 +108,19 @@ async function ensureSSMParametersExist(region) {
112108 ) ;
113109}
114110
115- async function createIAMResources ( accountId ) {
116- const workerRoleArn = await createWorkerRole ( accountId ) ;
111+ async function createIAMResources ( accountId , taskRoleName ) {
112+ const workerRoleArn = await createWorkerRole ( accountId , taskRoleName ) ;
117113
118114 return {
119115 workerRoleArn
120116 } ;
121117}
122118
123- async function createWorkerRole ( accountId ) {
119+ async function createWorkerRole ( accountId , taskRoleName ) {
124120 const iam = new AWS . IAM ( ) ;
125121
126122 try {
127- const res = await iam . getRole ( { RoleName : ECS_WORKER_ROLE_NAME } ) . promise ( ) ;
123+ const res = await iam . getRole ( { RoleName : taskRoleName } ) . promise ( ) ;
128124 return res . Role . Arn ;
129125 } catch ( err ) {
130126 debug ( err ) ;
@@ -145,7 +141,7 @@ async function createWorkerRole(accountId) {
145141 ]
146142 } ) ,
147143 Path : '/' ,
148- RoleName : ECS_WORKER_ROLE_NAME
144+ RoleName : taskRoleName
149145 } )
150146 . promise ( ) ;
151147
@@ -231,7 +227,7 @@ async function createWorkerRole(accountId) {
231227 await iam
232228 . attachRolePolicy ( {
233229 PolicyArn : createPolicyResp . Policy . Arn ,
234- RoleName : ECS_WORKER_ROLE_NAME
230+ RoleName : taskRoleName
235231 } )
236232 . promise ( ) ;
237233
0 commit comments