Skip to content

Restore RDS DB from snapshot#120

Open
tewfik-ghariani wants to merge 11 commits intoNixOS:masterfrom
tewfik-ghariani:rds-snapshot
Open

Restore RDS DB from snapshot#120
tewfik-ghariani wants to merge 11 commits intoNixOS:masterfrom
tewfik-ghariani:rds-snapshot

Conversation

@tewfik-ghariani
Copy link
Copy Markdown
Contributor

This PR introduces the possibility of restoring an RDS DB from snapshot.
Given that the RDS DB instance restored is automatically placed in the default SG, added the support for immediately modifying it to apply the submitted VPC SG

Additionally, the RDS module has been converted to boto3 instead of boto2

Other changes

  • RDS Subnet group: fix the destroy operation
  • Example file of RDS DB in VPC
  • Blackify
  • Upgrading boto3 version and re-locking poetry

cc @grahamc, @adisbladis, @RaitoBezarius

Copy link
Copy Markdown
Member

@RaitoBezarius RaitoBezarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on handling better errors and a new test, so thank you! Otherwise, it would be awesome to cut this PR into 3 PRs:

(1) Boto3 port.
(2) RDS snapshot feature.
(3) Unrelated minor changes like those on RDS subnets.

Anyway, except those points, LGTM.

subnet_group: Optional[str]
vpc_security_groups: Optional[Sequence[str]] = None
rds_dbinstance_security_groups: Optional[Sequence[str]] = None
vpc_security_groups: Optional[Sequence[str]] = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is it still relevant to keep Optional ? Same for the line below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still relevant of course, the 'vpc_security_groups' can be omitted since it's optional but by default it would have the empty array value.


self.rds_dbinstance_port = int(dbinstance.endpoint[1])
self.rds_dbinstance_endpoint = "%s:%d" % dbinstance.endpoint
self.rds_dbinstance_id = dbinstance["DBInstanceIdentifier"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have abstracted the AWS strings into a String Enum enum.Enum, rather than multiplying hardcoded references to it, that way, it's easy to change them in all the relevant places. But it can be done in a further PR IMHO.

def __init__(self, name: str, config: nixops.resources.ResourceEval):
super(RDSDbSubnetGroupDefinition, self).__init__(name, config)

self.group_name: str = self.config.name
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was mostly about RDS snapshot & boto 3 port, is this change really required in this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to mainly fix the destroy operation bug related to the subnet-group resource but also to streamline the resource definition and follow the standard

region = nixops.util.attr_property("region", None)
description = nixops.util.attr_property("description", None)
subnet_ids = nixops.util.attr_property("subnet_ids", [], "json")
access_key_id = nixops.util.attr_property("accessKeyId", None)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it required now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was moved from line 39 to this place so that in the new line 83, we would access it from the defn directly instead of from the config

Copy link
Copy Markdown
Contributor Author

@tewfik-ghariani tewfik-ghariani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @RaitoBezarius

Actually I split my commits in a way that each change would be viewed on its own to make the review easier

(1) Boto3 port. fb5ea12
(2) RDS snapshot feature. 576b701
(3) Unrelated minor changes like those on RDS subnets. :

subnet_group: Optional[str]
vpc_security_groups: Optional[Sequence[str]] = None
rds_dbinstance_security_groups: Optional[Sequence[str]] = None
vpc_security_groups: Optional[Sequence[str]] = []
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still relevant of course, the 'vpc_security_groups' can be omitted since it's optional but by default it would have the empty array value.

def __init__(self, name: str, config: nixops.resources.ResourceEval):
super(RDSDbSubnetGroupDefinition, self).__init__(name, config)

self.group_name: str = self.config.name
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to mainly fix the destroy operation bug related to the subnet-group resource but also to streamline the resource definition and follow the standard

region = nixops.util.attr_property("region", None)
description = nixops.util.attr_property("description", None)
subnet_ids = nixops.util.attr_property("subnet_ids", [], "json")
access_key_id = nixops.util.attr_property("accessKeyId", None)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was moved from line 39 to this place so that in the new line 83, we would access it from the defn directly instead of from the config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants