-
Notifications
You must be signed in to change notification settings - Fork 13
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
RFC 0011: Allow Intrinsic Functions and Pseudo-Parameter References in DeletionPolicy and UpdateReplacePolicy RFC #74
Merged
MalikAtalla-AWS
merged 2 commits into
aws-cloudformation:main
from
MalikAtalla-AWS:deletionPolicy
May 31, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
# Allow Intrinsic Functions and Pseudo-Parameter References in `DeletionPolicy` and `UpdateReplacePolicy` Resource attributes | ||
|
||
* **Original Author(s):**: @mingujo | ||
* **Tracking Issue**: [Tracking Issue](https://github.com/aws-cloudformation/cfn-language-discussion/issues/11) | ||
|
||
# Summary | ||
|
||
Use CloudFormation [intrinsic functions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html) and [Pseudo-Parameter references](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html) to dynamically determine a value for DeletionPolicy and UpdateReplacePolicy Resource attributes | ||
|
||
# Examples | ||
|
||
### Use [Ref](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) | ||
```json | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Parameters": { | ||
"DeletionPolicyParam": { | ||
"Type": "String", | ||
"AllowedValues": ["Delete", "Retain", "Snapshot"], | ||
"Default": "Delete" | ||
}, | ||
"UpdateReplacePolicyParam": { | ||
"Type": "String", | ||
"AllowedValues": ["Delete", "Retain", "Snapshot"], | ||
"Default": "Delete" | ||
} | ||
}, | ||
"Resources": { | ||
"Table": { | ||
"Type": "AWS::DynamoDB::Table", | ||
"Properties": { | ||
"KeySchema": [ | ||
{ | ||
"AttributeName" : "primaryKey", | ||
"KeyType" : "HASH" | ||
} | ||
] | ||
}, | ||
"DeletionPolicy": { "Ref": "DeletionPolicyParameter" }, | ||
"UpdateReplacePolicy": { "Ref": "UpdateReplacePolicyParam" } | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Use [Conditions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html) and [Fn::If](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#intrinsic-function-reference-conditions-if) based on Parameters | ||
```json | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Parameters": { | ||
"Stage": { | ||
"Type": "String", | ||
"AllowedValues": ["Prod", "Staging", "Dev"] | ||
} | ||
}, | ||
"Conditions": { | ||
"IsProd" : {"Fn::Equals" : [{"Ref" : "Stage"}, "Prod"]} | ||
}, | ||
"Resources": { | ||
"Table": { | ||
"Type": "AWS::DynamoDB::Table", | ||
"Properties": { | ||
"KeySchema": [ | ||
{ | ||
"AttributeName" : "primaryKey", | ||
"KeyType" : "HASH" | ||
} | ||
] | ||
}, | ||
"DeletionPolicy": { | ||
"Fn::If": [ "IsProd", "Retain", "Delete" ] | ||
}, | ||
"UpdateReplacePolicy": { | ||
"Fn::If": [ "IsProd", "Retain", "Delete" ] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Use [Fn::FindInMap](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html) and `AWS::Region` Pseudo-Parameter | ||
```json | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Parameters": { | ||
"Stage": { | ||
"Type": "String", | ||
"AllowedValues": ["Prod", "Staging", "Dev"] | ||
} | ||
}, | ||
"Mappings" : { | ||
"RegionMap" : { | ||
"us-east-1" : { | ||
"DeletionPolicy": "Retain", | ||
"UpdateReplacePolicy": "Retain" | ||
}, | ||
"us-west-1" : { | ||
"DeletionPolicy": "Delete", | ||
"UpdateReplacePolicy": "Delete" | ||
}, | ||
"eu-west-1" : { | ||
"DeletionPolicy": "Retain", | ||
"UpdateReplacePolicy": "Delete" | ||
}, | ||
"ap-southeast-1" : { | ||
"DeletionPolicy": "Delete", | ||
"UpdateReplacePolicy": "Delete" | ||
} | ||
} | ||
}, | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"DeletionPolicy": { | ||
"Fn::FindInMap" : [ | ||
"RegionMap", | ||
{ "Ref" : "AWS::Region" }, | ||
"DeletionPolicy" | ||
] | ||
}, | ||
"UpdateReplacePolicy": { | ||
"Fn::FindInMap" : [ | ||
"RegionMap", | ||
{ "Ref" : "AWS::Region" }, | ||
"UpdateReplacePolicy" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
# Motivation | ||
|
||
CloudFormation customers expect to use conditions and intrinsic functions as values for `DeletionPolicy` and `UpdateReplacePolicy` Resource attributes as they can do elsewhere in the template. | ||
The main ask from our customers was to allow them to vary DeletionPolicy and UpdateReplacePolicy values based on development stage, which tends to be passed in as a parameter, e.g., allow resource deletion in Dev stages but not Prod. This RFC proposes to support not only such use case but also other intrinsic function usages and Pseudo-parameter references. | ||
|
||
* References | ||
* https://github.com/aws-cloudformation/cfn-language-discussion/issues/58 (149 thumbs up) | ||
* https://github.com/aws/aws-cli/issues/3825 | ||
|
||
# Details | ||
* The following intrinsic functions will be supported. | ||
* [Ref](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) | ||
* [Fn::FindInMap](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html) | ||
* [Fn::If](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html#intrinsic-function-reference-conditions-if) | ||
|
||
|
||
* The following Pseudo-Parameters will be supported | ||
* `AWS::AccountId`, `AWS::Region`, `AWS::Partition` | ||
|
||
# Limitation | ||
|
||
**Note:** This limitation is due to underlying implementation constraints. In the fullness of time, this limitation should be removed. | ||
|
||
Does not support expressions containing references to *[Resource properties](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)* or *certain pseudo parameters* | ||
* Unsupported Pseudo-Parameters | ||
* `AWS::StackId`, `AWS::StackName`, `AWS::NotificationArns`, `AWS::URLSuffix`, `AWS::NoValue` | ||
|
||
|
||
# FAQ | ||
* How about other Resource attributes such as CreationPolicy, DependsOn, Metadata, UpdatePolicy? | ||
* They are out of scope of this RFC. | ||
|
||
|
||
* Will this be supported by CFN Lint (linter check for CFN template)? | ||
* The AWS CloudFormation Linter (cfn-lint) will be updated to validate function and Pseudo-parameter usages under Resource attributes. | ||
|
||
# Appendix | ||
## More examples | ||
### Use [Fn::FindInMap](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html) and `AWS::Partition` | ||
```json | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Parameters": { | ||
"Stage": { | ||
"Type": "String", | ||
"AllowedValues": ["Prod", "Staging", "Dev"] | ||
} | ||
}, | ||
"Mappings" : { | ||
"PartitionMap" : { | ||
"aws" : { | ||
"DeletionPolicy": "Retain", | ||
"UpdateReplacePolicy": "Retain" | ||
}, | ||
"aws-cn" : { | ||
"DeletionPolicy": "Delete", | ||
"UpdateReplacePolicy": "Delete" | ||
}, | ||
"aws-us-gov" : { | ||
"DeletionPolicy": "Retain", | ||
"UpdateReplacePolicy": "Delete" | ||
} | ||
} | ||
}, | ||
"Resources": { | ||
"Table": { | ||
"Type": "AWS::DynamoDB::Table", | ||
"Properties": { | ||
"KeySchema": [ | ||
{ | ||
"AttributeName" : "primaryKey", | ||
"KeyType" : "HASH" | ||
} | ||
] | ||
}, | ||
"DeletionPolicy": { | ||
"Fn::FindInMap" : [ | ||
"PartitionMap", | ||
{ "Ref" : "AWS::Partition" }, | ||
"DeletionPolicy" | ||
] | ||
}, | ||
"UpdateReplacePolicy": { | ||
"Fn::FindInMap" : [ | ||
"PartitionMap", | ||
{ "Ref" : "AWS::Partition" }, | ||
"UpdateReplacePolicy" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Use [Fn::FindInMap](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html) and `AWS::Region` Pseudo-Parameter in YAML | ||
```yaml | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
Parameters: | ||
Stage: | ||
Type: String | ||
AllowedValues: | ||
- Prod | ||
- Staging | ||
- Dev | ||
Mappings: | ||
RegionMap: | ||
us-east-1: | ||
DeletionPolicy: Retain | ||
UpdateReplacePolicy: Retain | ||
us-west-1: | ||
DeletionPolicy: Delete | ||
UpdateReplacePolicy: Delete | ||
eu-west-1: | ||
DeletionPolicy: Retain | ||
UpdateReplacePolicy: Delete | ||
ap-northeast-1: | ||
DeletionPolicy: Delete | ||
UpdateReplacePolicy: Delete | ||
Resources: | ||
Bucket: | ||
Type: "AWS::S3::Bucket" | ||
DeletionPolicy: !FindInMap [RegionMap, !Ref "AWS::Region", DeletionPolicy] | ||
UpdateReplacePolicy: !FindInMap [RegionMap, !Ref "AWS::Region", DeletionPolicy] | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why does it have this limitation?
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.
Thanks for the question. These are short-term limitations due to underlying implementation constraints. In the fullness of time, these limitations should be removed.