-
Notifications
You must be signed in to change notification settings - Fork 1
Add DatabaseReplica component #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
73d3500
Add replicateSourceDb param to database constructor for DB replica in…
mbareta c430e2d
Do not set KMS and password since those are inherited from primary DB
mbareta 3abe50a
Add DatabaseReplica component
mbareta 141d2ed
Clean up
mbareta 3473c75
Update README
mbareta 5ae42bf
Update README
mbareta 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 hidden or 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 hidden or 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,126 @@ | ||
| import * as aws from '@pulumi/aws'; | ||
| import * as pulumi from '@pulumi/pulumi'; | ||
| import { commonTags } from '../constants'; | ||
|
|
||
| export type DatabaseReplicaArgs = { | ||
| /** | ||
| * ARN of the primary DB that we want to replicate. | ||
| */ | ||
| replicateSourceDb: pulumi.Input<string>; | ||
| /** | ||
| * DB subnet group name. Should be the same as primary instance. | ||
| * * If primary DB is instance of studion:Database, it can be accessed as | ||
| * `db.dbSubnetGroup.name`. | ||
| */ | ||
| dbSubnetGroupName: pulumi.Input<string>; | ||
| /** | ||
| * DB security group ID. Should be the same as primary instance. | ||
| * If primary DB is instance of studion:Database, it can be accessed as | ||
| * `db.dbSecurityGroup.id`. | ||
| */ | ||
| dbSecurityGroupId: pulumi.Input<string>; | ||
| /** | ||
| * IAM Monitoring role. Should be the same as primary instance. | ||
| */ | ||
| monitoringRole?: aws.iam.Role; | ||
| /** | ||
| * Specifies if the RDS instance is multi-AZ. Defaults to false. | ||
| */ | ||
| multiAz?: pulumi.Input<boolean>; | ||
| /** | ||
| * Specifies whether any database modifications are applied immediately, | ||
| * or during the next maintenance window. Default is false. | ||
| */ | ||
| applyImmediately?: pulumi.Input<boolean>; | ||
| /** | ||
| * The allocated storage in gibibytes. Defaults to 20GB. | ||
| */ | ||
| allocatedStorage?: pulumi.Input<number>; | ||
| /** | ||
| * The upper limit to which Amazon RDS can automatically scale | ||
| * the storage of the DB instance. Defaults to 100GB. | ||
| */ | ||
| maxAllocatedStorage?: pulumi.Input<number>; | ||
| /** | ||
| * The instance type of the RDS instance. Defaults to 'db.t4g.micro'. | ||
| */ | ||
| instanceClass?: pulumi.Input<string>; | ||
| /** | ||
| * A map of tags to assign to the resource. | ||
| */ | ||
| tags?: pulumi.Input<{ | ||
| [key: string]: pulumi.Input<string>; | ||
| }>; | ||
| }; | ||
|
|
||
| const defaults = { | ||
| multiAz: false, | ||
| applyImmediately: false, | ||
| skipFinalSnapshot: false, | ||
| allocatedStorage: 20, | ||
| maxAllocatedStorage: 100, | ||
| instanceClass: 'db.t4g.micro', | ||
| enableMonitoring: false, | ||
| }; | ||
|
|
||
| export class DatabaseReplica extends pulumi.ComponentResource { | ||
| name: string; | ||
| instance: aws.rds.Instance; | ||
| monitoringRole?: aws.iam.Role; | ||
|
|
||
| constructor( | ||
| name: string, | ||
| args: DatabaseReplicaArgs, | ||
| opts: pulumi.ComponentResourceOptions = {}, | ||
| ) { | ||
| super('studion:DatabaseReplica', name, {}, opts); | ||
|
|
||
| this.name = name; | ||
|
|
||
| const argsWithDefaults = Object.assign({}, defaults, args); | ||
| this.monitoringRole = argsWithDefaults.monitoringRole; | ||
| this.instance = this.createDatabaseInstance(args); | ||
|
|
||
| this.registerOutputs(); | ||
| } | ||
|
|
||
| private createDatabaseInstance(args: DatabaseReplicaArgs) { | ||
| const argsWithDefaults = Object.assign({}, defaults, args); | ||
| const stack = pulumi.getStack(); | ||
|
|
||
| const monitoringOptions = | ||
| argsWithDefaults.enableMonitoring && this.monitoringRole | ||
| ? { | ||
| monitoringInterval: 60, | ||
| monitoringRoleArn: this.monitoringRole.arn, | ||
| performanceInsightsEnabled: true, | ||
| performanceInsightsRetentionPeriod: 7, | ||
| } | ||
| : {}; | ||
|
|
||
| const instance = new aws.rds.Instance( | ||
| `${this.name}-rds`, | ||
| { | ||
| identifierPrefix: `${this.name}-`, | ||
| engine: 'postgres', | ||
| engineVersion: '15.5', | ||
| allocatedStorage: argsWithDefaults.allocatedStorage, | ||
| maxAllocatedStorage: argsWithDefaults.maxAllocatedStorage, | ||
| instanceClass: argsWithDefaults.instanceClass, | ||
| dbSubnetGroupName: argsWithDefaults.dbSubnetGroupName, | ||
| vpcSecurityGroupIds: [argsWithDefaults.dbSecurityGroupId], | ||
| storageEncrypted: true, | ||
| multiAz: argsWithDefaults.multiAz, | ||
| publiclyAccessible: false, | ||
| applyImmediately: argsWithDefaults.applyImmediately, | ||
| autoMinorVersionUpgrade: true, | ||
| maintenanceWindow: 'Mon:07:00-Mon:07:30', | ||
| replicateSourceDb: argsWithDefaults.replicateSourceDb, | ||
| ...monitoringOptions, | ||
| tags: { ...commonTags, ...argsWithDefaults.tags }, | ||
| }, | ||
| { parent: this } | ||
| ); | ||
| return instance; | ||
| } | ||
| } | ||
This file contains hidden or 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.
@ikovac should I put defaults from this and the Database component to constants file and reuse or do we want to have them separate? I just noticed we have
skipFinalSnapshothere which does not apply to replica.Also, based on our offline talk, replicas can have multiAz too.
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 think we can keep them separate