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

[Core] Fn.ConditionIf doesn't capitalise properties name. #10895

Closed
pivstone opened this issue Oct 15, 2020 · 2 comments
Closed

[Core] Fn.ConditionIf doesn't capitalise properties name. #10895

pivstone opened this issue Oct 15, 2020 · 2 comments
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@pivstone
Copy link

pivstone commented Oct 15, 2020

When we put the nested resource properties in the Fn.ConditionIf, the output template doesn't capitalise those fields name. For NodeJs, we can change the name to Capital one, but for Typescript, we can't do it. The type check force us to use lower case.

Reproduction Steps

Here is the demo code

const cdk = require('@aws-cdk/core');
const dynamodb = require('@aws-cdk/aws-dynamodb');
const YAML = require('yamljs');

class HelloCdkStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new dynamodb.CfnTable(this, 'items', {
      keySchema: [
        {
          attributeName: 'itemId',
          keyType: dynamodb.AttributeType.STRING,
        },
      ],
      tableName: 'items',
      provisionedThroughput: {
        readCapacityUnits: 10,
        writeCapacityUnits: 10,
      },
      globalSecondaryIndexes: [
        cdk.Fn.conditionIf(
          'HasGlobalSecondaryIndex1',
          {
            IndexName: cdk.Fn.ref('IndexName'),
            KeySchema: [
              {
                AttributeName: cdk.Fn.ref('HashKeyName'),
                KeyType: 'HASH',
              },
            ],
            Projection: {
              ProjectionType: 'ALL',
            },
            ProvisionedThroughput: {
              readCapacityUnits: cdk.Fn.ref('readCapacityUnits'),
              writeCapacityUnits: cdk.Fn.ref('writeCapacityUnits'),
            },
          },
          cdk.Aws.NO_VALUE
        ),
      ],
    });
  }
}

const stackName = 'stack';
const app = new cdk.App();
new HelloCdkStack(app, stackName);
app.synth();
const { template } = app.synth().getStackByName(stackName);
console.log(YAML.stringify(template, 20, 2));

The output:

Resources:
  items:
    Type: 'AWS::DynamoDB::Table'
    Properties:
      KeySchema:
        -
          AttributeName: itemId
          KeyType: S
      GlobalSecondaryIndexes:
        -
          'Fn::If':
            - HasGlobalSecondaryIndex1
            -
              IndexName:
                Ref: IndexName
              KeySchema:
                -
                  AttributeName:
                    Ref: HashKeyName
                  KeyType: HASH
              Projection:
                ProjectionType: ALL
              ProvisionedThroughput:
                readCapacityUnits:   // Here is problem
                  Ref: readCapacityUnits
                writeCapacityUnits:
                  Ref: writeCapacityUnits
            -
              Ref: 'AWS::NoValue'
      ProvisionedThroughput:
        ReadCapacityUnits: 10
        WriteCapacityUnits: 10
      TableName: items

What did you expect to happen?

Capitalise the parameter name in the ConditionIf

What actually happened?

Environment

  • CLI Version :
  • Framework Version: 1.67.0
  • Node.js Version: v12.13.1
  • OS : macOS
  • Language (Version): TypeScript

Other


This is 🐛 Bug Report

@pivstone pivstone added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 15, 2020
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Oct 15, 2020
@pivstone pivstone changed the title [Core] Fn.ConditionIf doesn't capitalise parameter name. [Core] Fn.ConditionIf doesn't capitalise properties name. Oct 15, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 19, 2020

but for Typescript, we can't do it. The type check force us to use lower case.

You can always use as any to cast typechecks away.

Other than that, this is a duplicate of #8396

@rix0rrr rix0rrr closed this as completed Oct 19, 2020
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants