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

(documentDB): (Expose CACertificateIdentifier in L2 Construct) #28356

Closed
1 of 2 tasks
HaaLeo opened this issue Dec 13, 2023 · 2 comments · Fixed by #28791
Closed
1 of 2 tasks

(documentDB): (Expose CACertificateIdentifier in L2 Construct) #28356

HaaLeo opened this issue Dec 13, 2023 · 2 comments · Fixed by #28791
Labels
@aws-cdk/aws-docdb Related to Amazon DocumentDB effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@HaaLeo
Copy link

HaaLeo commented Dec 13, 2023

Describe the feature

Pls expose the CloudFormation CACertificateIdentifier property on the L2 construct docDb.DatabaseCluster

Use Case

With that one does not have to use Aspects to set the ca certificate

Proposed Solution

If one can guide me I might be able to submit a PR myself.

Other Information

Right now one can use Aspects as a workaround:

import * as docDb from 'aws-cdk-lib/aws-docdb';

let database: docDb.DatabaseCluster;

// ... 

cdk.Aspects.of(database).add({
    visit: (node) => {
        if (node instanceof docDb.CfnDBInstance) {
            node.addPropertyOverride('CACertificateIdentifier', 'rds-ca-rsa2048-g1');
        }
    }
});

Acknowledgements

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

CDK version used

2.100.0

Environment details (OS name and version, etc.)

macOS 14.2

@HaaLeo HaaLeo added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2023
@github-actions github-actions bot added the @aws-cdk/aws-docdb Related to Amazon DocumentDB label Dec 13, 2023
@pahud
Copy link
Contributor

pahud commented Dec 14, 2023

Yeah it would be great to expose that as an optional property.

Aside from Aspects, another option is like this:

export class DemoStack extends Stack {
  readonly fn: lambda.IFunction;
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props);

    const cluster = new docdb.DatabaseCluster(this, 'Database', {
      masterUser: {
        username: 'myuser', // NOTE: 'admin' is reserved by DocumentDB
        excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/" and is also used for eventually created rotations
        secretName: '/myapp/mydocdb/masteruser', // optional, if you prefer to specify the secret name
      },
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
      instances: 3,
      vpcSubnets: {
        subnetType: ec2.SubnetType.PUBLIC,
      },
      vpc: getDefaultVpc(this),
    });

   this.overrideCustomProperty('AWS::DocDB::DBInstance', 'CACertificateIdentifier', 'rds-ca-rsa2048-g1', [cluster]);

  }
  private overrideCustomProperty(resourceType: string, overrideKey: string, overrideValue: string, children?: IConstruct[]) {
    (children ?? this.node.children).forEach((child) => {
      if(CfnResource.isCfnResource(child) && child.cfnResourceType == resourceType ) {
        child.addPropertyOverride(overrideKey, overrideValue)
      } else {
        this.overrideCustomProperty(resourceType, overrideKey, overrideValue, child.node.children)
      }
    })
  }
}

And you can run multiple this.overrideCustomProperty() to override multiple properties.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2023
mergify bot added a commit to brokad/aws-cdk that referenced this issue May 9, 2024
@mergify mergify bot closed this as completed in #28791 May 9, 2024
mergify bot pushed a commit that referenced this issue May 9, 2024
Exposes the [CaCertificateIdentifier](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-docdb-dbinstance.html#cfn-docdb-dbinstance-cacertificateidentifier) property of [AWS::DocDB::DBInstance](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-docdb-dbinstance.html) in the L2 constructs `DatabaseCluster` and `DatabaseInstance` of `aws_docdb`. This allows specifying a custom CA identifier using the CaCertificate class.

Usage with `DatabaseCluster`:

```typescript
new DatabaseCluster(stack, 'Database', {
  // ...
  instanceType: InstanceType.of(InstanceClass.R5, InstanceSize.LARGE),
  instanceCaCertificate: CaCertificate.RDS_CA_RSA4096_G1,
  // ...
});
```

Usage with `DatabaseInstance`:

```typescript
new DatabaseInstance(stack, 'Instance', {
  cluster: databaseCluster,
  instanceType: InstanceType.of(InstanceClass.R5, InstanceSize.LARGE),
  caCertificate: CaCertificate.RDS_CA_RSA4096_G1,
});
```

This is modelled on #27138.

Closes #28356.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

github-actions bot commented May 9, 2024

⚠️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/aws-docdb Related to Amazon DocumentDB effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants