Skip to content

Commit 4e7d638

Browse files
authored
fix: use role ARN (not name) for execution/task role in ECS task defs (#2887)
Using the role name in the ECS task definition results in CloudFormation stack drift. ECS returns the fully-qualified ARN when describing the task def, which fails the comparison to the stack template's value. Example drift seen in the CFN console for a Copilot-created service stack: ``` Expected: "ExecutionRoleArn": "proton-pilot-example-test-front-end-ExecutionRole-1CY6ZXWZU4YQF", "TaskRoleArn": "proton-pilot-example-test-front-end-TaskRole-1NMILHSCBDBTT" Actual: "ExecutionRoleArn": "arn:aws:iam::123456789012:role/proton-pilot-example-test-front-end-ExecutionRole-1CY6ZXWZU4YQF", "TaskRoleArn": "arn:aws:iam::123456789012:role/proton-pilot-example-test-front-end-TaskRole-1NMILHSCBDBTT" ``` By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
1 parent a6c8406 commit 4e7d638

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

internal/pkg/deploy/cloudformation/stack/testdata/stacklocal/override-cf.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
- FARGATE
1111
Cpu: !Ref TaskCPU
1212
Memory: !Ref TaskMemory
13-
ExecutionRoleArn: !Ref ExecutionRole
14-
TaskRoleArn: !Ref TaskRole
13+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
14+
TaskRoleArn: !GetAtt TaskRole.Arn
1515
ContainerDefinitions:
1616
- Name: !Ref WorkloadName
1717
Image: !Ref ContainerImage

internal/pkg/deploy/cloudformation/stack/testdata/workloads/job-test.stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ Resources:
117117
Memory: !Ref TaskMemory
118118
EphemeralStorage:
119119
SizeInGiB: 200
120-
ExecutionRoleArn: !Ref ExecutionRole
121-
TaskRoleArn: !Ref TaskRole
120+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
121+
TaskRoleArn: !GetAtt TaskRole.Arn
122122
ContainerDefinitions:
123123
- Name: !Ref WorkloadName
124124
Image: !Ref ContainerImage

internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-prod.stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ Resources:
6868
- FARGATE
6969
Cpu: !Ref TaskCPU
7070
Memory: !Ref TaskMemory
71-
ExecutionRoleArn: !Ref ExecutionRole
72-
TaskRoleArn: !Ref TaskRole
71+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
72+
TaskRoleArn: !GetAtt TaskRole.Arn
7373
ContainerDefinitions:
7474
- Name: !Ref WorkloadName
7575
Image: !Ref ContainerImage

internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-staging.stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ Resources:
6868
- FARGATE
6969
Cpu: !Ref TaskCPU
7070
Memory: !Ref TaskMemory
71-
ExecutionRoleArn: !Ref ExecutionRole
72-
TaskRoleArn: !Ref TaskRole
71+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
72+
TaskRoleArn: !GetAtt TaskRole.Arn
7373
ContainerDefinitions:
7474
- Name: !Ref WorkloadName
7575
Image: !Ref ContainerImage

internal/pkg/deploy/cloudformation/stack/testdata/workloads/svc-test.stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ Resources:
6868
- FARGATE
6969
Cpu: !Ref TaskCPU
7070
Memory: !Ref TaskMemory
71-
ExecutionRoleArn: !Ref ExecutionRole
72-
TaskRoleArn: !Ref TaskRole
71+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
72+
TaskRoleArn: !GetAtt TaskRole.Arn
7373
ContainerDefinitions:
7474
- Name: !Ref WorkloadName
7575
Image: !Ref ContainerImage

internal/pkg/deploy/cloudformation/stack/testdata/workloads/worker-test.stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Resources:
4848
- FARGATE
4949
Cpu: !Ref TaskCPU
5050
Memory: !Ref TaskMemory
51-
ExecutionRoleArn: !Ref ExecutionRole
52-
TaskRoleArn: !Ref TaskRole
51+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
52+
TaskRoleArn: !GetAtt TaskRole.Arn
5353
ContainerDefinitions:
5454
- Name: !Ref WorkloadName
5555
Image: !Ref ContainerImage

internal/pkg/template/templates/task/cf.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Resources:
6767
NetworkMode: awsvpc
6868
Cpu: !Ref TaskCPU
6969
Memory: !Ref TaskMemory
70-
ExecutionRoleArn: !If [HasExecutionRole, !Ref ExecutionRole, !Ref DefaultExecutionRole]
71-
TaskRoleArn: !If [HasTaskRole, !Ref TaskRole, !Ref DefaultTaskRole]
70+
ExecutionRoleArn: !If [HasExecutionRole, !Ref ExecutionRole, !GetAtt DefaultExecutionRole.Arn]
71+
TaskRoleArn: !If [HasTaskRole, !Ref TaskRole, !GetAtt DefaultTaskRole.Arn]
7272
DefaultExecutionRole:
7373
Metadata:
7474
'aws:copilot:description': 'An IAM Role for the Fargate agent to make AWS API calls on your behalf'

internal/pkg/template/templates/workloads/partials/cf/fargate-taskdef-base-properties.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ EphemeralStorage:
1010
SizeInGiB: {{.Storage.Ephemeral}}
1111
{{- end}}
1212
{{- end}}
13-
ExecutionRoleArn: !Ref ExecutionRole
14-
TaskRoleArn: !Ref TaskRole
13+
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
14+
TaskRoleArn: !GetAtt TaskRole.Arn

0 commit comments

Comments
 (0)