From 6a9e92f84e1946309e450743d75b32ce76fcd59e Mon Sep 17 00:00:00 2001 From: Evan Haston Date: Wed, 24 Apr 2024 17:06:17 -0400 Subject: [PATCH 1/3] feat: Add support for task and execution role ARNs in action.yml and index.js --- action.yml | 6 ++++++ index.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/action.yml b/action.yml index 462ad136..48040b30 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,12 @@ inputs: command: description: 'The command used by ECS to start the container image' required: false + task-role-arn: + description: 'The ARN of the IAM role that the ECS container will assume' + required: false + execution-role-arn: + description: 'The ARN of the IAM role that the ECS task execution role will assume' + required: false outputs: task-definition: description: 'The path to the rendered task definition file' diff --git a/index.js b/index.js index c15ba606..d7f7e46f 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,9 @@ async function run() { const logConfigurationOptions = core.getInput("log-configuration-options", { required: false }); const dockerLabels = core.getInput('docker-labels', { required: false }); const command = core.getInput('command', { required: false }); + const taskRoleArn = core.getInput('task-role-arn', { required: false }); + const executionRoleArn = core.getInput('execution-role-arn', { required: false }); + // Parse the task definition const taskDefPath = path.isAbsolute(taskDefinitionFile) ? @@ -37,6 +40,8 @@ async function run() { throw new Error('Invalid task definition: Could not find container definition with matching name'); } containerDef.image = imageURI; + containerDef.executionRoleArn = taskRoleArn; + containerDef.taskRoleArn = executionRoleArn if (command) { containerDef.command = command.split(' ') From bcab98a0b5639e17c5040ab4e25e0d2507de56ed Mon Sep 17 00:00:00 2001 From: Evan Haston Date: Wed, 24 Apr 2024 17:08:17 -0400 Subject: [PATCH 2/3] Fix missing semicolon in index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d7f7e46f..77d5b1bf 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ async function run() { } containerDef.image = imageURI; containerDef.executionRoleArn = taskRoleArn; - containerDef.taskRoleArn = executionRoleArn + containerDef.taskRoleArn = executionRoleArn; if (command) { containerDef.command = command.split(' ') From 40510261b5a8db3d7918dfc403cf4882ed5405c2 Mon Sep 17 00:00:00 2001 From: Evan Haston Date: Wed, 24 Apr 2024 17:51:12 -0400 Subject: [PATCH 3/3] Fix task and execution role ARN assignment in index.js --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 77d5b1bf..ccddceb0 100644 --- a/index.js +++ b/index.js @@ -40,8 +40,7 @@ async function run() { throw new Error('Invalid task definition: Could not find container definition with matching name'); } containerDef.image = imageURI; - containerDef.executionRoleArn = taskRoleArn; - containerDef.taskRoleArn = executionRoleArn; + if (command) { containerDef.command = command.split(' ') @@ -126,6 +125,14 @@ async function run() { }) } + if (taskRoleArn) { + taskDefContents.taskRoleArn = taskRoleArn; + } + + if (executionRoleArn) { + taskDefContents.executionRoleArn = executionRoleArn; + } + // Write out a new task definition file var updatedTaskDefFile = tmp.fileSync({ tmpdir: process.env.RUNNER_TEMP,