-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: apply resource conditions to DeploymentPreference resources #1578
Conversation
Deployed the following template (after a local transform) and verified that it created the correct resources (and didn't create others). NOTE: This will cause some redeployments for customers where some resources will be removed from their templates. In the case of the following template: Resources created:
Resources no longer created (will be deleted):
Transform: AWS::Serverless-2016-10-31
Conditions:
Condition1:
Fn::Equals:
- true
- true
Condition2:
Fn::Equals:
- true
- false
Condition3:
Fn::Equals:
- true
- false
Parameters:
MyFalseParameter:
Type: String
Default: False
Resources:
MinimalFunction:
Condition: Condition1
Type: 'AWS::Serverless::Function'
Properties:
Handler: hello.handler
InlineCode: |
def hi():
print("hi")
Runtime: python2.7
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery2Minutes
MinimalFunctionWithMinimalDeploymentPreference:
Type: 'AWS::Serverless::Function'
Condition: Condition2
Properties:
InlineCode: |
def hi():
print("hi")
Handler: hello.handler
Runtime: python2.7
AutoPublishAlias: livewithdeployment
DeploymentPreference:
Type: Canary10Percent5Minutes
MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms:
Type: 'AWS::Serverless::Function'
Condition: Condition2
Properties:
InlineCode: |
def hi():
print("hi")
Handler: hello.handler
Runtime: python2.7
AutoPublishAlias: livewithdeploymentwithhooksandalarms
DeploymentPreference:
Type: Linear10PercentEvery2Minutes
Hooks:
PreTraffic: !Ref MySanityTestFunction
PostTraffic: !Ref MyValidationTestFunction
MySanityTestFunction:
Type: 'AWS::Serverless::Function'
Condition: Condition3
Properties:
Handler: hello.handler
Runtime: python2.7
InlineCode: |
def hi():
print("hi")
DeploymentPreference:
Enabled: False
MyValidationTestFunction:
Type: 'AWS::Serverless::Function'
Condition: Condition3
Properties:
Handler: hello.handler
Runtime: python2.7
InlineCode: |
def hi():
print("hi")
DeploymentPreference:
Enabled: !Ref MyFalseParameter |
This PR potentially removes resources on a new deployment, the resources that will be removed should have not have been used. This PR does fixes an underlying bug and should have been the expected behavior to start with. Any concerns on this PR? |
8edfda3
to
10c0b99
Compare
0de6ed0
to
2ec132f
Compare
Pushed new changes to enable the condition fix only if the feature flag "deployment_preference_condition_fix" is enabled. Existing behavior will be used for any account ID that is not allow-listed (see test case "tests/translator/input/function_with_deployment_preference_condition_without_condition_fix.yaml"). As the above comment mentioned, the resources that will be removed should have not been used. We decided to use a feature flag to gate it before we are certain that removing the resources are safe. More investigation will be done but is not under the current scope |
@hawflau Can we just add the removal of these into a new Property? That way back compat is kept but customers have a way to remove the behavior as needed? |
Codecov Report
@@ Coverage Diff @@
## develop #1578 +/- ##
===========================================
+ Coverage 93.58% 94.44% +0.86%
===========================================
Files 90 98 +8
Lines 6124 7254 +1130
Branches 1260 1505 +245
===========================================
+ Hits 5731 6851 +1120
- Misses 183 195 +12
+ Partials 210 208 -2
Continue to review full report at Codecov.
|
Updated to add a new property Examples:
@jfuss Can you check if that makes sense to you? |
# FIXME: We should support not only true/false, but also yes/no, on/off? See https://yaml.org/type/bool.html | ||
passthrough_condition = True if passthrough_condition in [True, "true", "True"] else False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to sam_resources
@@ -860,6 +889,40 @@ def _validate_deployment_preference_and_add_update_policy( | |||
"UpdatePolicy", deployment_preference_collection.update_policy(self.logical_id).to_dict() | |||
) | |||
|
|||
def _resolve_property_to_boolean( | |||
self, | |||
property_value: Union[bool, str, dict], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can it be anything else? like int
and float
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, can't they only be string, boolean or intrinsic?
https://yaml.org/type/bool.html
Issue #, if available:
N/A
Description of changes:
Bug fix. Adds conditions from the Serverless::Function resource to the CodeDeploy resources that are created when using
DeploymentPreference
. Previously, these resources were added even if the resources that use them were not included based on resource conditions.Description of how you validated changes:
Updated tests, deployed sample template and verified that resources were created correctly.
Potentially a breaking change if there is a dependency on the resources that were created before hand (when there was a bug, and conditions were not passed through to deployment preference resources). With this change, those resources that were previously created will be up for deletion. If those resources are being used elsewhere, those will start breaking now.
Checklist:
make pr
passesexamples/2016-10-31
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.