-
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(aws-rds): add support for parameter groups #729
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { DBClusterParameterGroupName } from './rds.generated'; | ||
|
||
/** | ||
* A cluster parameter group | ||
*/ | ||
export abstract class ClusterParameterGroupRef extends cdk.Construct { | ||
/** | ||
* Import a parameter group | ||
*/ | ||
public static import(parent: cdk.Construct, id: string, props: ClusterParameterGroupRefProps): ClusterParameterGroupRef { | ||
return new ImportedClusterParameterGroup(parent, id, props); | ||
} | ||
|
||
/** | ||
* Name of this parameter group | ||
*/ | ||
public abstract readonly parameterGroupName: DBClusterParameterGroupName; | ||
|
||
/** | ||
* Export this parameter group | ||
*/ | ||
public export(): ClusterParameterGroupRefProps { | ||
return { | ||
parameterGroupName: new DBClusterParameterGroupName( | ||
new cdk.Output(this, 'ParameterGroupName', { value: this.parameterGroupName }).makeImportValue()) | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Properties to reference a cluster parameter group | ||
*/ | ||
export interface ClusterParameterGroupRefProps { | ||
parameterGroupName: DBClusterParameterGroupName; | ||
} | ||
|
||
/** | ||
* An imported cluster parameter group | ||
*/ | ||
class ImportedClusterParameterGroup extends ClusterParameterGroupRef { | ||
public readonly parameterGroupName: DBClusterParameterGroupName; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: ClusterParameterGroupRefProps) { | ||
super(parent, id); | ||
this.parameterGroupName = props.parameterGroupName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { ClusterParameterGroupRef } from './cluster-parameter-group-ref'; | ||
import { Parameters } from './props'; | ||
import { cloudformation, DBClusterParameterGroupName } from './rds.generated'; | ||
|
||
/** | ||
* Properties for a cluster parameter group | ||
*/ | ||
export interface ClusterParameterGroupProps { | ||
/** | ||
* Database family of this parameter group | ||
*/ | ||
family: string; | ||
|
||
/** | ||
* Description for this parameter group | ||
*/ | ||
description: string; | ||
|
||
/** | ||
* The parameters in this parameter group | ||
*/ | ||
parameters?: Parameters; | ||
} | ||
|
||
/** | ||
* Defina a cluster parameter group | ||
*/ | ||
export class ClusterParameterGroup extends ClusterParameterGroupRef { | ||
public readonly parameterGroupName: DBClusterParameterGroupName; | ||
private readonly parameters: Parameters = {}; | ||
|
||
constructor(parent: cdk.Construct, id: string, props: ClusterParameterGroupProps) { | ||
super(parent, id); | ||
|
||
const resource = new cloudformation.DBClusterParameterGroupResource(this, 'Resource', { | ||
description: props.description, | ||
family: props.family, | ||
parameters: new cdk.Token(() => this.parameters), | ||
}); | ||
|
||
for (const [key, value] of Object.entries(props.parameters || {})) { | ||
this.setParameter(key, value); | ||
} | ||
|
||
this.parameterGroupName = resource.ref; | ||
} | ||
|
||
/** | ||
* Set a single parameter in this parameter group | ||
*/ | ||
public setParameter(key: string, value: string | undefined) { | ||
if (value === undefined && key in this.parameters) { | ||
delete this.parameters[key]; | ||
} | ||
if (value !== undefined) { | ||
this.parameters[key] = value; | ||
} | ||
} | ||
|
||
/** | ||
* Remove a previously-set parameter from this parameter group | ||
*/ | ||
public removeParameter(key: string) { | ||
this.setParameter(key, undefined); | ||
} | ||
|
||
/** | ||
* Validate this construct | ||
*/ | ||
public validate(): string[] { | ||
if (Object.keys(this.parameters).length === 0) { | ||
return ['At least one parameter required, call setParameter().']; | ||
} | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we also add
removeParameter
?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 thought
setParameter(name, undefined)
would fulfil that purpose.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.
Let's just sprinkle some sugar on top of it. Wouldn't be my first guess when looking to remove a parameter 😉