Skip to content

Commit

Permalink
feat(rds): enable grantDataApiAccess method for imported database c…
Browse files Browse the repository at this point in the history
…luster (aws#31280)

### Issue # (if applicable)

Closes aws#31116 .

### Reason for this change



It was not possible to call the `grantDataApiAccess` method for an imported database cluster.

Because the imported database cluster always has the `enableDataApi` with false.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-rds/lib/cluster.ts#L983

```ts
class ImportedDatabaseCluster extends DatabaseClusterBase implements IDatabaseCluster {
  // ...
  protected readonly enableDataApi = false;
```

But the `grantDataApiAccess` throws an error when the `enableDataApi` is set to false.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-rds/lib/cluster.ts#L523-L526

```ts
  public grantDataApiAccess(grantee: iam.IGrantable): iam.Grant {
    if (this.enableDataApi === false) {
      throw new Error('Cannot grant Data API access when the Data API is disabled');
    }
    // ...
}
```

### Description of changes



Added the property `dataApiEnabled` to attributes for the imported database cluster.

If the `dataApiEnabled` to the attributes is set to true, the `enableDataApi` in the imported cluster will be set to true and the `grantDataApiAccess` can be called.

### Description of how you validated changes



Unit and integ tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
go-to-k authored Oct 3, 2024
1 parent 19ee46d commit 3c92012
Show file tree
Hide file tree
Showing 15 changed files with 2,840 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3c92012

Please sign in to comment.