copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Environment Specific Patches?

Open ssyberg opened this issue 1 year ago • 7 comments

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 avatar Mar 28 '24 15:03 ssyberg

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

ssyberg avatar Mar 28 '24 15:03 ssyberg

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.

dannyrandall avatar Mar 29 '24 20:03 dannyrandall

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!

ssyberg avatar Apr 01 '24 11:04 ssyberg

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.

github-actions[bot] avatar Jun 01 '24 00:06 github-actions[bot]

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?

ssyberg avatar Jun 12 '24 19:06 ssyberg

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

huanjani avatar Jun 14 '24 20:06 huanjani

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?

ssyberg avatar Jun 17 '24 14:06 ssyberg

Hi @huanjani just wanted to bump this, I just had an unfortunate incident while making changes to my staging tasks, since the cfn is not environment specific it ended up messing up production! If there's an easy way to add conditionals to break these out it would be most appreciated!

ssyberg avatar Jul 29 '24 19:07 ssyberg

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.

github-actions[bot] avatar Sep 28 '24 00:09 github-actions[bot]

This issue is closed due to inactivity. Feel free to reopen the issue if you have any further questions!

github-actions[bot] avatar Oct 13 '24 00:10 github-actions[bot]