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.41k stars 397 forks source link

Environment Specific Patches? #5747

Open ssyberg opened 3 months ago

ssyberg commented 3 months ago

Not sure if this is a feature request or just a question, but I'm trying to figure out how to implement different patches per environment or at least set parameters/variables per environment?

For example, if I have a staging and production environment how can I add this patch such that it doesn't get added to both load balancers or at least has slightly different values for each environment?

- op: add
  path: /Resources/HTTPSListenerRuleRedirect
  value:
    Metadata:
        'aws:copilot:description': 'An HTTPS listener redirect rule'
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      Actions:
        - Type: redirect
          RedirectConfig:
            Protocol: HTTPS
            Port: '443'
            Host: 'production.com'
            Path: '/foo'
            Query: '#{query}'
            StatusCode: HTTP_301
      Conditions:
        - Field: host-header
          HostHeaderConfig:
            Values:
              - production.org
        - Field: path-pattern
          PathPatternConfig:
            Values:
              - /
      Priority: 40000
      ListenerArn: !GetAtt EnvControllerAction.HTTPSListenerArn
ssyberg commented 3 months ago

Relevant gitter convo: https://matrix.to/#/!QdxoBcgpJveoAoIPCc:gitter.im/$mrqCm6roJzNE2AGhtgilJA5S-0ytAQrUZXUe_fOJZJA?via=gitter.im&via=matrix.org&via=matrix.martinides.de

dannyrandall commented 3 months ago

Hey @ssyberg! You could try using Conditions like in this example for addons: https://github.com/aws/copilot-cli/issues/4229. You can use patches to create conditions for each environment, and then add that Condition to the resources you want to conditionally create for each specific environment.

ssyberg commented 3 months ago

Hey @ssyberg! You could try using Conditions like in this example for addons: #4229. You can use patches to create conditions for each environment, and then add that Condition to the resources you want to conditionally create for each specific environment.

Ooh yes that seems like it could work, ty!

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 60 days with no response activity. Remove the stale label, add a comment, or this will be closed in 14 days.

ssyberg commented 2 weeks ago

I thought I understood what to do here but I think it would be helpful to 1. get an example patch that has a condition and 2. ideally get an answer on if you have have multiple patch files per service, otherwise you'd need to include them all in a single file which seems messy?

huanjani commented 2 weeks ago

Hi, @ssyberg!

Here is an example patch that changes an existing Condition: https://github.com/aws/copilot-cli/issues/5680#issuecomment-1984790251 and here is one that adds a Condition: https://github.com/aws/copilot-cli/issues/5387#issue-1943249493

And in answer to your other question, no, you cannot have multiple patch files

ssyberg commented 1 week ago

Thanks @huanjani though I think I don't know CFN well enough to totally understand this. Can you tell me exactly the steps I would take here to set up one set of ALB rules for staging and another set for production?