aws / copilot-cli

The AWS Copilot CLI is a tool for developers to build, release and operate production ready containerized applications on AWS App Runner or Amazon ECS on AWS Fargate.
https://aws.github.io/copilot-cli/
Apache License 2.0
3.42k stars 397 forks source link

Export service's TaskRole in Cloudformation output for add-on importing #5818

Open gautam-nutalapati opened 1 month ago

gautam-nutalapati commented 1 month ago

We create KMS key in add-ons, and would like to restrict it to service task role. Can we expose task role ARN in Cloudformation so we can use it in KMC access policy in addons?

UPDATE: Please note that unlike applying policy to task role via addons, in this case we need to use task role ARN in addons. Refer: KMS key-policies

huanjani commented 1 month ago

Hi, @gautam-nutalapati!

You can create a Parameters file for your addons template that refers to your Task Role ARN. See https://aws.github.io/copilot-cli/docs/developing/addons/workload/#customizing-the-parameters-section.

huanjani commented 1 month ago

In .../addons/addons.parameters.yml:

Parameters:
    TaskRoleArn: !GetAtt TaskRole.Arn
gautam-nutalapati commented 1 month ago

I tried this and got the error ValidationError: Circular dependency between resources: [TaskDefinition, AddonsStack, Service, TaskRole]

Steps:

I guess this approach may not work as TaskRole resource refers to policies created by AddOns and referring to TaskRole in turn in AddOns may be causing this issue.

I don't know if there's a way to solve this unless we create KMS key in main stack itself. For now, we will continue to hard code ARNs. :/

Let us know your thoughts.

Lou1415926 commented 1 month ago

@gautam-nutalapati Hi hi! Have you tried moving DataEncryptionKey into the main stack via. yaml patch?