-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: idiomize cloudformation intrinsics and pseudo parameters #1428
Conversation
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.
Mostly goodness! A couple of comments though... Nothing too bad.
As discussed, it may be wise to revert the Aws
changes as they'll unfortunately collide with #1436 in ways that might result in hardcore merge conflict pain.
@@ -7,7 +7,7 @@ | |||
"pkglint": "tools/pkglint/bin/pkglint -f ." | |||
}, | |||
"devDependencies": { | |||
"@types/node": "^8.10.38", | |||
"@types/node": "8.10.38", |
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 the pinning?
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.
For some reason it seems like npm keeps moving us to 10.x when we build in CI and then we get these unsolicited breakage of master. Other ideas?
packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts
Show resolved
Hide resolved
* @param value A string, such as "A", that you want to compare against a list of strings. | ||
* @returns an FnCondition token | ||
*/ | ||
public static containsCondition(listOfStrings: string[], value: string): FnCondition { |
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.
I don't like the Condition
suffix everywhere. It looks mighty redundant. In the case of containsConditions
here, the name even would imply I'm checking if some array contains a FnCondition
reference, which is not what it's doing.
I would at the very least remove the Condition
suffix, and maybe ideally move this into a Condition
class (Condition.equals(val, val)
, Condition.contains(arr, val)
, ...)
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.
Some suffix/prefix is needed for two reasons:
- Many of the condition functions use names that are reserved words (such as "if", "and", "or").
- It should be possible for users to easily distinguish between condition functions and normal functions.
I agree about "containsCondition" implying the wrong thing.
Alternative options:
- A prefix "condition":
conditionContains
,conditionAnd
, etc - A postfix "cond":
containsCond
,andCond
- A prefix "cond":
condContains
,condIf
Any other ideas?
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.
I prefer going for a prefix (since we don't want to go full on namespace/class, that's what's closest), preferably condition
(the short-hand doesn't improve much of anything).
@@ -90,6 +100,8 @@ export class Parameter extends Referenceable { | |||
super(parent, name); | |||
this.properties = props; | |||
this.value = new Ref(this); | |||
this.valueAsString = this.value.toString(); | |||
this.valueAsList = this.value.toList(); |
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.
Am always somewhat annoyed that only one of those is valid for a given entity... And we allows both. But I guess we can't do better, can we?
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.
I was thinking that we can also provide StringParameter
and StringListParamater
as sugar classes that will make this a bit more strongly-typed.
rule.addAssertion(new FnEquals('lhs', 'rhs'), 'lhs equals rhs'); | ||
rule.addAssertion(new FnNot(new FnAnd(new FnContains([ 'hello', 'world' ], "world"))), 'some assertion'); | ||
rule.addAssertion(Fn.equalsCondition('lhs', 'rhs'), 'lhs equals rhs'); | ||
rule.addAssertion(Fn.notCondition(Fn.andCondition(Fn.containsCondition([ 'hello', 'world' ], "world"))), 'some assertion'); |
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.
This... is where the helpers I mentioned previously come in handy... This Polish notation nonsense is a recipe for disaster. Also, it's so verbose!
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.
See my note about not over indexing on the CFN conditions programming model. Especially not as part of this change.
Reverted the pseudo parameter change to avoid conflict with #1436 |
Fixes #742 Built on top of #1428 BREAKING CHANGE: AWS resource-related classes have been changed to conform to API guidelines: - `XxxRef` abstract classes are now `IXxx` interfaces - `XxxRefProps` are now `XxxImportProps` - `XxxRef.import(...)` are now `Xxx.import(...)` accept `XxxImportProps` and return `IXxx` - `export(): XxxImportProps` is now defined in `IXxx` and implemented by imported resources - Lambda's static "metric" methods moved from `lambda.FunctionRef` to `lambda.Function`. - Route53 record classes now require a `zone` when created (not assuming zone is the parent construct).
Thanks so much for taking the time to contribute to the AWS CDK ❤️ We will shortly assign someone to review this pull request and help get it
|
Refactor CloudFormation intrinsic functions so that they will have a more idiomatic shape. They have been converted from classes (e.g.
new FnJoin(...)
) to static methods (e.g.Fn.join(...)
). Condition functions are mapped toFn.conditionXxx
and return anFnCondition
object.Furthermore, return type of these static methods are now tokens represented as the resolved type (i.e.
string
orstring[]
) instead ofCloudFormationToken
objects. This allows using these functions and pseudo parameters naturally (instead of requiring the use of.toString()
or.toList()
).Fixes #202
BREAKING CHANGE: CloudFormation intrinsic functions are now represented as static methods under the
Fn
class (e.g.Fn.join(...)
instead ofnew FnJoin(...).toString()
).Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.