-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-rds): add support for parameter groups (#729)
Now supports (Cluster) Parameter Groups. This is required to support Aurora 5.7 engines (in particular, PostgreSQL with Aurora). Fixes #719.
- Loading branch information
Showing
8 changed files
with
197 additions
and
6 deletions.
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