-
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
Now supports (Cluster) Parameter Groups. This is required to support Aurora 5.7 engines (in particular, PostgreSQL with Aurora). Fixes #719.
- Loading branch information
Rico Huijbers
committed
Sep 17, 2018
1 parent
815915e
commit 37d5944
Showing
7 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
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()) | ||
}; | ||
} | ||
|
||
/** | ||
* Set a parameter on this parameter group | ||
*/ | ||
public abstract setParameter(key: string, value: string | undefined): void; | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
/** | ||
* Set a parameter on this parameter group | ||
*/ | ||
public setParameter(_key: string, _value: string | undefined) { | ||
// FIXME: Add annotation that we're dropping this on the floor | ||
} | ||
} |
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,70 @@ | ||
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; | ||
} | ||
} | ||
|
||
/** | ||
* 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