Skip to content
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

cdk.Fn: improve conditionEquals parameters types #30036

Open
2 tasks done
AllanOricil opened this issue May 1, 2024 · 1 comment
Open
2 tasks done

cdk.Fn: improve conditionEquals parameters types #30036

AllanOricil opened this issue May 1, 2024 · 1 comment
Labels
@aws-cdk/core Related to core CDK functionality effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@AllanOricil
Copy link

Describe the feature

Because cdk.Fn.conditionEquals is expecting 2 parameters of type any

image

people can logically think that the following condition, which compares "string" with "string", should work

cdk.Fn.conditionEquals(props.createBucketParameter.valueAsString, "true"),

However, it does not. The proper way to configure this condition is to pass CfnParameter reference as follows,

cdk.Fn.conditionEquals(props.createBucketParameter, "true"),

which leads to this template piece:

image

At first, this behavior seems illogical, because:

  1. when reading a code that isn't using asValueString, the comparison is clearly between "CfnParameter" and "string" types, which, because of the lack of proper type definition for parameters, won't be considered as an option

  2. the types in the conditionEquals method are of "any", which can make people think that they must compare similar types, like string and string, boolean and boolean, or even CfnParameter to CfnParameter. However, as shown previously, when using the type CfnParameters, the first argument must be its reference and not itsvalueAsString.

Use Case

Developers will clearly know what types can be compared in cdk.Fn.conditionEquals when writting or reading code, which improves DX, and therefore efficiency.

Proposed Solution

Add all type permutations that are possible for those 2 parameters in cdk.Fn.conditionEquals

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.138

Environment details (OS name and version, etc.)

macos

@AllanOricil AllanOricil added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 1, 2024
@khushail
Copy link
Contributor

khushail commented May 1, 2024

Hey @AllanOricil , thanks for reporting this. From the Read me of conditionequals , it is apparent as what you are saying is true.

Fn.conditionEquals('Production', environmentParameter),

it seems confusing to look at this code inline documentation though as mentioned by you-

public static conditionEquals(lhs: any, rhs: any): ICfnRuleConditionExpression {

I can see this PR was submitted to bring Cloudformation parameter constraint only and it would be helpful to have the clear docs to understand the functionality. Please feel free to submit a PR.

Since this might be a breaking change, I am adding the required labels for Team's input here.

@khushail khushail added p2 effort/small Small work item – less than a day of effort needs-review and removed needs-triage This issue or PR still needs to be triaged. labels May 1, 2024
@khushail khushail removed their assignment May 8, 2024
@moelasmar moelasmar added the @aws-cdk/core Related to core CDK functionality label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

3 participants