@@ -11,10 +11,7 @@ const AWS = require('aws-sdk');
11
11
12
12
const { ensureParameterExists } = require ( './legacy/aws-util' ) ;
13
13
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' ) ;
18
15
19
16
const getAccountId = require ( '../aws/aws-get-account-id' ) ;
20
17
@@ -48,12 +45,11 @@ class PlatformECS {
48
45
49
46
async init ( ) {
50
47
await setDefaultAWSCredentials ( AWS ) ;
51
-
52
48
this . accountId = await getAccountId ( ) ;
53
49
54
50
await ensureSSMParametersExist ( this . platformOpts . region ) ;
55
51
await ensureS3BucketExists ( 'global' , this . s3LifecycleConfigurationRules ) ;
56
- await createIAMResources ( this . accountId ) ;
52
+ await createIAMResources ( this . accountId , this . platformOpts . taskRoleName ) ;
57
53
}
58
54
59
55
async createWorker ( ) { }
@@ -112,19 +108,19 @@ async function ensureSSMParametersExist(region) {
112
108
) ;
113
109
}
114
110
115
- async function createIAMResources ( accountId ) {
116
- const workerRoleArn = await createWorkerRole ( accountId ) ;
111
+ async function createIAMResources ( accountId , taskRoleName ) {
112
+ const workerRoleArn = await createWorkerRole ( accountId , taskRoleName ) ;
117
113
118
114
return {
119
115
workerRoleArn
120
116
} ;
121
117
}
122
118
123
- async function createWorkerRole ( accountId ) {
119
+ async function createWorkerRole ( accountId , taskRoleName ) {
124
120
const iam = new AWS . IAM ( ) ;
125
121
126
122
try {
127
- const res = await iam . getRole ( { RoleName : ECS_WORKER_ROLE_NAME } ) . promise ( ) ;
123
+ const res = await iam . getRole ( { RoleName : taskRoleName } ) . promise ( ) ;
128
124
return res . Role . Arn ;
129
125
} catch ( err ) {
130
126
debug ( err ) ;
@@ -145,7 +141,7 @@ async function createWorkerRole(accountId) {
145
141
]
146
142
} ) ,
147
143
Path : '/' ,
148
- RoleName : ECS_WORKER_ROLE_NAME
144
+ RoleName : taskRoleName
149
145
} )
150
146
. promise ( ) ;
151
147
@@ -231,7 +227,7 @@ async function createWorkerRole(accountId) {
231
227
await iam
232
228
. attachRolePolicy ( {
233
229
PolicyArn : createPolicyResp . Policy . Arn ,
234
- RoleName : ECS_WORKER_ROLE_NAME
230
+ RoleName : taskRoleName
235
231
} )
236
232
. promise ( ) ;
237
233
0 commit comments